I am using a Custom deserializer to parse the json node to appropriate subclass. When some of properties have umlaut characters , code fails at parser.readValueAsTree(). I tried using JsonDeserializer over property as well but it is never been called. I want to strip these accent characters from parser and then deserialize it. Is there a way to modify some of the key value properties to remove these characters and then read the json node?
Below is the code :
import java.io.IOException;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.TreeNode;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
import com.fasterxml.jackson.databind.node.TextNode;
public class CustomAddressDeserializer extends StdDeserializer<Address> {
protected CustomAddressDeserializer() {
super(Address.class);
}
@Override
public Address deserialize(JsonParser parser, DeserializationContext ctxt)
throws IOException, JsonProcessingException {
TreeNode node = parser.readValueAsTree();
//code fails at this point
}
}
json node is a list of addresses which contains city with accent characters
JSONpayload and code which reproduces this bug?Jackson. Try to create a simple test where you provideJSONpayload as aString. How do you read receive thisJSON? Do you read it from file? Try to read it is asUTF-8. Jackson ObjectMapper with UTF-8 encoding?