-
Notifications
You must be signed in to change notification settings - Fork 321
Closed
Description
I found this code fails while it works with replacing new ObjectMapper(new MessagePackFactory()) with new ObjectMapper().
public static class MyIntegerSerializer
extends JsonSerializer<Integer>
{
@Override
public void serialize(Integer value, JsonGenerator gen, SerializerProvider serializers)
throws IOException, JsonProcessingException
{
gen.writeNumber(String.valueOf(value));
}
}
public static class MyIntegerDeserializer
extends JsonDeserializer<Integer>
{
@Override
public Integer deserialize(JsonParser p, DeserializationContext ctxt)
throws IOException, JsonProcessingException
{
return p.getNumberValue().intValue();
}
}
public static void main(String[] args)
throws IOException
{
ObjectMapper objectMapper = new ObjectMapper(new MessagePackFactory());
objectMapper.registerModule(
new SimpleModule()
.addSerializer(Integer.class, new MyIntegerSerializer())
.addDeserializer(Integer.class, new MyIntegerDeserializer())
);
ByteArrayOutputStream out = new ByteArrayOutputStream();
objectMapper.writeValue(out, 42);
Integer integer = objectMapper.readValue(out.toByteArray(), Integer.class);
System.out.println(integer);
}
>>>> com.fasterxml.jackson.databind.JsonMappingException: writeNumber(String encodedValue) isn't supported yet
Metadata
Metadata
Assignees
Labels
No labels