ObjectMapper是否应该与只有私有成员,没有构造函数和没有getter / setter的类一起工作?
我试过这个,但它没有解决问题。
mapper.setVisibility(JsonMethod.FIELD, JsonAutoDetect.Visibility.ANY);
答案 0 :(得分:0)
http://www.baeldung.com/jackson-field-serializable-deserializable-or-not
static class MyDtoAccessLevel {
private String stringValue = "hidden";
}
public static void main(String[] args) throws JsonProcessingException {
ObjectMapper mapper = new ObjectMapper();
mapper.setVisibility(PropertyAccessor.FIELD, Visibility.ANY);
MyDtoAccessLevel dtoObject = new MyDtoAccessLevel();
System.out.println(mapper.writeValueAsString(dtoObject));
//prints {"stringValue":"hidden"}
}