Search in sources :

Example 1 with SchematizerImpl

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);
}
Also used : SchematizerImpl(org.apache.felix.schematizer.impl.SchematizerImpl) Converter(org.osgi.util.converter.Converter) TypeReference(org.osgi.util.converter.TypeReference) Test(org.junit.Test)

Example 2 with SchematizerImpl

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);
}
Also used : SchematizerImpl(org.apache.felix.schematizer.impl.SchematizerImpl) Converter(org.osgi.util.converter.Converter) TypeReference(org.osgi.util.converter.TypeReference) Test(org.junit.Test)

Aggregations

SchematizerImpl (org.apache.felix.schematizer.impl.SchematizerImpl)2 Test (org.junit.Test)2 Converter (org.osgi.util.converter.Converter)2 TypeReference (org.osgi.util.converter.TypeReference)2