use StdSerializer and StdDeserializer

This commit is contained in:
DOHA 2016-07-26 20:38:59 +02:00
parent ea867019d5
commit ad14e7c262
2 changed files with 25 additions and 8 deletions

View File

@ -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<Car> {
public class CustomCarDeserializer extends StdDeserializer<Car> {
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();

View File

@ -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<Car>
public class CustomCarSerializer extends StdSerializer<Car>
{
public CustomCarSerializer() { }
private static final long serialVersionUID = 1396140685442227917L;
public CustomCarSerializer() {
this(null);
}
public CustomCarSerializer(final Class<Car> t) {
super(t);
}
@Override
public void serialize(final Car car, final JsonGenerator jsonGenerator, final SerializerProvider serializer) throws IOException, JsonProcessingException