use StdSerializer and StdDeserializer
This commit is contained in:
parent
ea867019d5
commit
ad14e7c262
|
@ -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();
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue