@Test public void deserialize() throws IOException { ComponentXO componentXO = new FooComponentXO(new BarComponentXO(new DefaultComponentXO())); when(componentXOFactory.createComponentXO()).thenReturn(componentXO); String json = "{\"id\": \"theid\", \"foo\": \"fiz\", \"bar\": \"biz\"}"; JsonParser jsonParser = jsonFactory.createParser(json); jsonParser.setCodec(objectMapper); ComponentXO result = underTest.deserialize(jsonParser, deserializationContext); assertThat(result, notNullValue()); assertThat(result.getId(), equalTo("theid")); FooComponentXO fooComponentXO = getDecoratedEntity(result, FooComponentXO.class); assertThat(fooComponentXO, notNullValue()); assertThat(fooComponentXO.getFoo(), equalTo("fiz")); BarComponentXO barComponentXO = getDecoratedEntity(result, BarComponentXO.class); assertThat(barComponentXO, notNullValue()); assertThat(barComponentXO.getBar(), equalTo("biz")); }
@Override public ComponentXO deserialize(final JsonParser jsonParser, final DeserializationContext ctxt) throws IOException { JsonNode jsonNode = jsonParser.getCodec().readTree(jsonParser); ComponentXO componentXO = componentXOFactory.createComponentXO(); objectMapper.readerForUpdating(componentXO).readValue(jsonNode); for (ComponentXODeserializerExtension componentXODeserializerExtension : componentXODeserializerExtensions) { componentXO = componentXODeserializerExtension.updateComponentXO(componentXO, jsonNode); } return componentXO; }
ComponentXODeserializer extends JsonDeserializer<ComponentXO> { @Override public ComponentXO deserialize(final JsonParser jsonParser, final DeserializationContext ctxt) throws IOException { JsonNode jsonNode = jsonParser.getCodec().readTree(jsonParser); ComponentXO componentXO = componentXOFactory.createComponentXO(); objectMapper.readerForUpdating(componentXO).readValue(jsonNode); for (ComponentXODeserializerExtension componentXODeserializerExtension : componentXODeserializerExtensions) { componentXO = componentXODeserializerExtension.updateComponentXO(componentXO, jsonNode); } return componentXO; } }
ComponentXODeserializer extends JsonDeserializer<ComponentXO> { @Override public ComponentXO deserialize(final JsonParser jsonParser, final DeserializationContext ctxt) throws IOException { JsonNode jsonNode = jsonParser.getCodec().readTree(jsonParser); ComponentXO componentXO = componentXOFactory.createComponentXO(); objectMapper.readerForUpdating(componentXO).readValue(jsonNode); for (ComponentXODeserializerExtension componentXODeserializerExtension : componentXODeserializerExtensions) { componentXO = componentXODeserializerExtension.updateComponentXO(componentXO, jsonNode); } return componentXO; } ComponentXODeserializer(final ComponentXOFactory componentXOFactory,
                                 final ObjectMapper objectMapper,
                                 final Set<ComponentXODeserializerExtension> componentXODeserializerExtensions); }
ComponentXODeserializer extends JsonDeserializer<ComponentXO> { @Override public ComponentXO deserialize(final JsonParser jsonParser, final DeserializationContext ctxt) throws IOException { JsonNode jsonNode = jsonParser.getCodec().readTree(jsonParser); ComponentXO componentXO = componentXOFactory.createComponentXO(); objectMapper.readerForUpdating(componentXO).readValue(jsonNode); for (ComponentXODeserializerExtension componentXODeserializerExtension : componentXODeserializerExtensions) { componentXO = componentXODeserializerExtension.updateComponentXO(componentXO, jsonNode); } return componentXO; } ComponentXODeserializer(final ComponentXOFactory componentXOFactory,
                                 final ObjectMapper objectMapper,
                                 final Set<ComponentXODeserializerExtension> componentXODeserializerExtensions); @Override ComponentXO deserialize(final JsonParser jsonParser, final DeserializationContext ctxt); }
ComponentXODeserializer extends JsonDeserializer<ComponentXO> { @Override public ComponentXO deserialize(final JsonParser jsonParser, final DeserializationContext ctxt) throws IOException { JsonNode jsonNode = jsonParser.getCodec().readTree(jsonParser); ComponentXO componentXO = componentXOFactory.createComponentXO(); objectMapper.readerForUpdating(componentXO).readValue(jsonNode); for (ComponentXODeserializerExtension componentXODeserializerExtension : componentXODeserializerExtensions) { componentXO = componentXODeserializerExtension.updateComponentXO(componentXO, jsonNode); } return componentXO; } ComponentXODeserializer(final ComponentXOFactory componentXOFactory,
                                 final ObjectMapper objectMapper,
                                 final Set<ComponentXODeserializerExtension> componentXODeserializerExtensions); @Override ComponentXO deserialize(final JsonParser jsonParser, final DeserializationContext ctxt);  }