Created
November 6, 2019 12:00
-
-
Save billybong/b0732928f5f891d67b066dc315c9b7ec to your computer and use it in GitHub Desktop.
json-smart serialization fails without setter - treats bean field without setter as public
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import net.minidev.json.JSONObject; | |
import java.util.HashMap; | |
import java.util.Map; | |
public class ReproTest { | |
public static void main(String[] args) { | |
MyData data = new MyData("a"); | |
Map<String, Object> m = new HashMap<>(); | |
m.put("data", data); | |
System.out.println(new JSONObject(m)); | |
} | |
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; | |
} | |
*/ | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment