The problem with your example and Jackson is the default choice for JSON property names: Jackson will see isDoneand setDoneand select doneJSON as the property name. You can override this default selection using the annotation JsonProperty:
public class Status
{
private boolean isDone;
@JsonProperty("isDone")
public boolean isDone()
{
return this.isDone;
}
@JsonProperty("isDone")
public void setDone(boolean isDone)
{
this.isDone = isDone;
}
}
Then:
Status instance = new Status();
String jsonString = null;
instance.setDone(true);
ObjectMapper mapper = new ObjectMapper();
jsonString = mapper.writeValueAsString(instance);
jsonString { "isDone" : true }. , OutputStream ObjectMapper.writeValue(OutputStream, Object) Writer, ObjectMapper.writeValue(Writer, Object).
JsonProperty , . isDone JSON, .
JsonProperty setIsDone/getIsDone. .
: 5 . .
share