jBRGates version 1.1 B1 was released
see more http://jbrgates.brandao.org/.
1. Quick Reference.
The jBRGates is a lightweight library for serializing beans, maps, collections, arrays and Enum to Json and back again to beans.
1.1. Convert Java object to JSON.
The method JsonContext.encode(Object) convert a java object to json object.
Ex:
double[] javaObject = new double[]{1.0,25.0};
JsonContext context = new DefaultJsonContext();
String jsonObject = context.encode(javaObject);
Output:
[1.0, 25.0]
Ex2:
MyObject javaObject = new MyObject();
javaObject.filed1 = 12L;
javaObject.field2 = "Test";
JsonContext context = new DefaultJsonContext();
String jsonObject = context.encode(javaObject);
Output:
{"field1": 12, "field2": "Test"}
Ex3:
MyObject javaObject = new MyObject();
javaObject.filed1 = new Date();
javaObject.filed2 = MyEnum.VALUE1;
JsonContext context = new DefaultJsonContext();
String jsonObject = context.encode(javaObject);
Output:
{"field1": "2016-08-06T12:30:00.000Z", "field2": "VALUE1"}
1.2. Convert JSON to Java object.
The method JsonContext.decode(String) convert a json object to java object.
Ex:
String jsonObject = "[1.0, 25.0]";
JsonContext context = new DefaultJsonContext();
double[] javaObject = context.decode(jsonObject, double[].class);
Ex2:
String jsonObject = "{\"field1\": 12, \"field2\": \"Test\"};
JsonContext context = new DefaultJsonContext();
MyObject javaObject = context.decode(jsonObject, MyObject.class);
2. jBRGates Dependency.
<dependency>
<groupId>org.brandao</groupId>
<artifactId>jbrgates</artifactId>
<version>1.1-b1</version>
</dependency>
Nenhum comentário:
Postar um comentário