java之jackson

import com.fasterxml.jackson.databind.ObjectMapper;

GridMetaInt gridMetaInt = new GridMetaInt()
				.setXSize(1)
				.setYSize(1)
				.setXStart(1)
				.setYStart(3)
				.setXEnd(1)
				.setYEnd(5);
System.out.println("gridMetaInt = " + new Gson().toJson(gridMetaInt));
byte[] headerBytes=new ObjectMapper().writeValueAsBytes(gridMetaInt);
System.out.println("headerBytes = " + new String(headerBytes, "UTF-8"));
# gridMetaInt = {"xStart":1,"yStart":3,"xDelta":0.1,"yDelta":0.1,"xSize":2,"ySize":1,"xEnd":1,"yEnd":5}
# headerBytes = {"xstart":1,"ystart":3,"xdelta":0.1,"ydelta":0.1,"xsize":2,"ysize":1,"xend":1,"yend":5}

有时会出现大小写问题,加注解解决

@JsonAutoDetect(
		fieldVisibility = JsonAutoDetect.Visibility.ANY,
		getterVisibility = JsonAutoDetect.Visibility.NONE
)
@Data
@Accessors(chain = true)
public class GridMetaInt {
	private float xStart;
	private float yStart;
	private float xDelta;
	private float yDelta;
	private int xSize;
	private int ySize;
	private float xEnd;
	private float yEnd;
	@JsonProperty("unsigned")
	private boolean isUnsigned = false;
}

你可能感兴趣的:(JSON,java基础)