Skip to content

Instantly share code, notes, and snippets.

@billybong
Created November 6, 2019 12:00
Show Gist options
  • Save billybong/b0732928f5f891d67b066dc315c9b7ec to your computer and use it in GitHub Desktop.
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
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