use of org.apache.felix.schematizer.impl.SchematizerImpl in project felix by apache.
the class JsonDeserializationTest method testDeserializationWithCollection.
@Test
public void testDeserializationWithCollection() {
MyEmbeddedDTO2<String> embedded = new MyEmbeddedDTO2<>();
embedded.value = "one million dollars";
MyDTO2<MyEmbeddedDTO2<String>> dto = new MyDTO2<>();
dto.ping = "pppping";
dto.pong = 42;
dto.embedded = new ArrayList<>();
dto.embedded.add(embedded);
String serialized = new JsonSerializerImpl().serialize(dto).toString();
Converter c = new SchematizerImpl().type("MyDTO", "/embedded", new TypeReference<MyEmbeddedDTO2<String>>() {
}).schematize("MyDTO", new TypeReference<MyDTO2<MyEmbeddedDTO2<String>>>() {
}).converterFor("MyDTO");
MyDTO2<MyEmbeddedDTO2<String>> result = new JsonSerializerImpl().deserialize(new TypeReference<MyDTO2<MyEmbeddedDTO2<String>>>() {
}).convertWith(c).from(serialized);
assertEquals(dto.ping, result.ping);
assertEquals(dto.pong, result.pong);
assertEquals(dto.embedded.get(0).value, result.embedded.get(0).value);
}
use of org.apache.felix.schematizer.impl.SchematizerImpl in project felix by apache.
the class JsonDeserializationTest method testDeserialization.
@Test
public void testDeserialization() {
MyEmbeddedDTO embedded = new MyEmbeddedDTO();
embedded.marco = "mmmm";
embedded.polo = 24;
embedded.alpha = Alpha.B;
MyDTO dto = new MyDTO();
dto.ping = "pppping";
dto.pong = 42;
dto.count = Count.TWO;
dto.embedded = embedded;
Converter c = new SchematizerImpl().schematize("MyDTO", new TypeReference<MyDTO>() {
}).converterFor("MyDTO");
String serialized = new JsonSerializerImpl().serialize(dto).convertWith(c).toString();
MyDTO result = new JsonSerializerImpl().deserialize(MyDTO.class).convertWith(c).from(serialized);
assertEquals(dto.ping, result.ping);
assertEquals(dto.pong, result.pong);
assertEquals(dto.count, result.count);
assertEquals(dto.embedded.marco, result.embedded.marco);
assertEquals(dto.embedded.polo, result.embedded.polo);
assertEquals(dto.embedded.alpha, result.embedded.alpha);
}
Aggregations