Set view to deserialize JSON into entity

Hi,

This is rather a quick question, is there a way to deserialize a JSON Object into an Entity using an existing view for the Entity?

The case use is basically as follows. We call a REST method to another server of our application and we get an item persisted on the other server, serialized as a JSON Object with a view (“substance-view”). What we noticed is that when deserializing the JSON, the instances are created using the _minimal view for associated entities, thus losing some of the important information about this associated entity. So is there a way to specify which view to use or should we extend the _minimal (which I believe is a “dirtier” solution)?

Thanks beforehand!
Regards,
T.

PS: We are currently using the EntitySerializationAPI.

Hi,

EntitySerializationAPI while deserializing entities fills all entities attributes that are present in JSON.

See the following sample project and the com.company.ser.core.SampleIntegrationTest#testDeserialization test:

    @Test
    public void testDeserialization() {
        String json = "  {\n" +
                "    \"_entityName\": \"ser_Order\",\n" +
                "    \"id\": \"c87a6bee-8f00-243e-f8cf-a0c002c339e1\",\n" +
                "    \"createdBy\": \"admin\",\n" +
                "    \"price\": 1001.00,\n" +
                "    \"name\": \"A-001\",\n" +
                "    \"createTs\": \"2023-11-14 13:31:08.009\",\n" +
                "    \"company\":   {\n" +
                "    \"_entityName\": \"ser_Company\",\n" +
                "    \"id\": \"c1a04341-0700-baa8-fed2-172790863f96\",\n" +
                "    \"address\": \"NY city, NY\",\n" +
                "    \"createdBy\": \"admin\",\n" +
                "    \"city\": {\n" +
                "      \"_entityName\": \"ser_City\",\n" +
                "      \"id\": \"4417bbb5-8135-4188-5092-05a5076ea5bc\",\n" +
                "      \"code\": \"NY\",\n" +
                "      \"createdBy\": \"admin\",\n" +
                "      \"name\": \"New York\",\n" +
                "      \"createTs\": \"2023-11-14 13:30:41.866\",\n" +
                "      \"version\": 1,\n" +
                "      \"updateTs\": \"2023-11-14 13:30:41.866\"\n" +
                "    },\n" +
                "    \"name\": \"Amazon\",\n" +
                "    \"createTs\": \"2023-11-14 13:30:55.236\",\n" +
                "    \"version\": 1,\n" +
                "    \"updateTs\": \"2023-11-14 13:30:55.236\"\n" +
                "  },\n" +
                "    \"version\": 1,\n" +
                "    \"updateTs\": \"2023-11-14 13:31:08.009\"\n" +
                "  }";

        Order order = entitySerializationAPI.entityFromJson(json, metadata.getClass(Order.class));

        Company company = order.getCompany();
        assertNotNull(company);
        assertEquals("Amazon", company.getName());
        assertEquals("NY city, NY", company.getAddress());

        City city = company.getCity();
        assertNotNull(city);
        assertEquals("New York", city.getName());
        assertEquals("NY", city.getCode());
    }

All attributes from JSON are present in the entity.

The project:
cuba-entity-serialization.zip (100.8 KB)