package net.minidev.json.test;

import net.minidev.json.JSONObject;

import static org.junit.jupiter.api.Assertions.assertEquals;

import java.util.HashMap;
import java.util.Map;

import org.junit.jupiter.api.Test;

/**
 * https://github.com/netplex/json-smart-v2/issues/49
 */
public class SerializeReadonlyField {
	@Test
	public static void main(String[] args) {
		MyData data = new MyData("a");
		Map<String, Object> m = new HashMap<>();
		m.put("data", data);
		String a = new JSONObject(m).toString();
		assertEquals("{\"data\":{\"someField\":\"a\"}}", a.toString());
	}

	public static class MyData {
		private String someField;

		public MyData(String someField) {
			this.someField = someField;
		}

		public String getSomeField() {
			return someField;
		}

		// Remove comment to make serialization to work
		/*
		 * public void setSomeField(String someField) { this.someField = someField; }
		 */
	}
}

@@ -60,16 +60,51 @@
 NObject;
+%0Aimport net.minidev.json.JSONValue;
 %0A%0Aimport
@@ -171,21 +171,108 @@
 rt java.
-util.
+nio.file.Path;%0Aimport java.nio.file.Paths;%0Aimport java.util.HashMap;%0Aimport java.util.Linked
 HashMap;
@@ -335,13 +335,53 @@
 t;%0A%0A
+public class SerializeReadonlyField %7B%0A%09
 /**%0A 
+%09
 * ht
@@ -434,49 +434,12 @@
 49%0A 
+%09
 */%0A
-public class SerializeReadonlyField %7B%0A
 %09@Te
@@ -1029,10 +1029,332 @@
 %09 */%0A%09%7D%0A
+%09%0A%09/**%0A%09 * https://github.com/netplex/json-smart-v2/issues/59%0A%09 */%0A%09@Test%0A    public void test() %7B%0A%09%09// should not crash%0A        Map%3CString, Object%3E cachedTable1 = new LinkedHashMap%3C%3E();%0A        Iterable%3CPath%3E path = Paths.get(%22/%22);%0A        cachedTable1.put(%221%22, path);%0A        JSONValue.toJSONString(cachedTable1);%0A    %7D%0A
 %7D%0A

add a test for issue #59