using StdDeserializer

This commit is contained in:
DOHA 2016-07-25 13:54:18 +02:00
parent d848933f20
commit cc8632120c
5 changed files with 59 additions and 13 deletions

View File

@ -7,9 +7,19 @@ import java.util.List;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
public class CustomListDeserializer extends JsonDeserializer<List<ItemWithSerializer>> {
public class CustomListDeserializer extends StdDeserializer<List<ItemWithSerializer>> {
private static final long serialVersionUID = 1095767961632979804L;
public CustomListDeserializer() {
this(null);
}
public CustomListDeserializer(final Class<?> vc) {
super(vc);
}
@Override
public List<ItemWithSerializer> deserialize(final JsonParser jsonparser, final DeserializationContext context) throws IOException, JsonProcessingException {

View File

@ -8,12 +8,21 @@ import java.util.Date;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
public class CustomDateDeserializer extends JsonDeserializer<Date> {
public class CustomDateDeserializer extends StdDeserializer<Date> {
private static final long serialVersionUID = -5451717385630622729L;
private SimpleDateFormat formatter = new SimpleDateFormat("dd-MM-yyyy hh:mm:ss");
public CustomDateDeserializer() {
this(null);
}
public CustomDateDeserializer(final Class<?> vc) {
super(vc);
}
@Override
public Date deserialize(final JsonParser jsonparser, final DeserializationContext context) throws IOException, JsonProcessingException {
final String date = jsonparser.getText();

View File

@ -2,17 +2,26 @@ package com.baeldung.jackson.deserialization;
import java.io.IOException;
import com.baeldung.jackson.dtos.User;
import com.baeldung.jackson.dtos.Item;
import com.baeldung.jackson.dtos.User;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
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;
import com.fasterxml.jackson.databind.node.IntNode;
public class ItemDeserializer extends JsonDeserializer<Item> {
public class ItemDeserializer extends StdDeserializer<Item> {
private static final long serialVersionUID = 1883547683050039861L;
public ItemDeserializer() {
this(null);
}
public ItemDeserializer(final Class<?> vc) {
super(vc);
}
/**
* {"id":1,"itemNr":"theItem","owner":2}

View File

@ -4,15 +4,24 @@ import java.io.IOException;
import com.baeldung.jackson.dtos.ItemWithSerializer;
import com.baeldung.jackson.dtos.User;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
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;
import com.fasterxml.jackson.databind.node.IntNode;
public class ItemDeserializerOnClass extends JsonDeserializer<ItemWithSerializer> {
public class ItemDeserializerOnClass extends StdDeserializer<ItemWithSerializer> {
private static final long serialVersionUID = 5579141241817332594L;
public ItemDeserializerOnClass() {
this(null);
}
public ItemDeserializerOnClass(final Class<?> vc) {
super(vc);
}
/**
* {"id":1,"itemNr":"theItem","owner":2}

View File

@ -6,10 +6,19 @@ 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 RestLoaderRequestDeserializer extends JsonDeserializer<RestLoaderRequest<IEntity>> {
public class RestLoaderRequestDeserializer extends StdDeserializer<RestLoaderRequest<IEntity>> {
private static final long serialVersionUID = -4245207329377196889L;
public RestLoaderRequestDeserializer() {
this(null);
}
public RestLoaderRequestDeserializer(final Class<?> vc) {
super(vc);
}
@Override
public RestLoaderRequest<IEntity> deserialize(final JsonParser jp, final DeserializationContext ctxt) throws IOException, JsonProcessingException {