From ad14e7c2621bc42ad9e7e174d86364ee07dc77f0 Mon Sep 17 00:00:00 2001 From: DOHA Date: Tue, 26 Jul 2016 20:38:59 +0200 Subject: [PATCH] use StdSerializer and StdDeserializer --- .../objectmapper/CustomCarDeserializer.java | 14 +++++++++++--- .../objectmapper/CustomCarSerializer.java | 19 ++++++++++++++----- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/jackson/src/test/java/com/baeldung/jackson/objectmapper/CustomCarDeserializer.java b/jackson/src/test/java/com/baeldung/jackson/objectmapper/CustomCarDeserializer.java index 88ee1cd673..a3d0b377c6 100644 --- a/jackson/src/test/java/com/baeldung/jackson/objectmapper/CustomCarDeserializer.java +++ b/jackson/src/test/java/com/baeldung/jackson/objectmapper/CustomCarDeserializer.java @@ -7,18 +7,26 @@ import org.slf4j.LoggerFactory; import com.baeldung.jackson.objectmapper.dto.Car; import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.ObjectCodec; import com.fasterxml.jackson.databind.DeserializationContext; -import com.fasterxml.jackson.databind.JsonDeserializer; import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.deser.std.StdDeserializer; -public class CustomCarDeserializer extends JsonDeserializer { +public class CustomCarDeserializer extends StdDeserializer { + + private static final long serialVersionUID = -5918629454846356161L; private final Logger Logger = LoggerFactory.getLogger(getClass()); public CustomCarDeserializer() { + this(null); } + public CustomCarDeserializer(final Class vc) { + super(vc); + } + + + @Override public Car deserialize(final JsonParser parser, final DeserializationContext deserializer) throws IOException { final Car car = new Car(); diff --git a/jackson/src/test/java/com/baeldung/jackson/objectmapper/CustomCarSerializer.java b/jackson/src/test/java/com/baeldung/jackson/objectmapper/CustomCarSerializer.java index 08c7184d29..37bae829b7 100644 --- a/jackson/src/test/java/com/baeldung/jackson/objectmapper/CustomCarSerializer.java +++ b/jackson/src/test/java/com/baeldung/jackson/objectmapper/CustomCarSerializer.java @@ -1,16 +1,25 @@ package com.baeldung.jackson.objectmapper; +import java.io.IOException; + import com.baeldung.jackson.objectmapper.dto.Car; import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.JsonSerializer; import com.fasterxml.jackson.databind.SerializerProvider; +import com.fasterxml.jackson.databind.ser.std.StdSerializer; -import java.io.IOException; - -public class CustomCarSerializer extends JsonSerializer +public class CustomCarSerializer extends StdSerializer { - public CustomCarSerializer() { } + + private static final long serialVersionUID = 1396140685442227917L; + + public CustomCarSerializer() { + this(null); + } + + public CustomCarSerializer(final Class t) { + super(t); + } @Override public void serialize(final Car car, final JsonGenerator jsonGenerator, final SerializerProvider serializer) throws IOException, JsonProcessingException