[英]Failed to decode VALUE_STRING as base64
I am trying to Deserialize a json using fasterxml jackson , one of the fields in Json is a string but i need to read the same in a byte array PFB the Bean and main class 我试图使用fastxml jackson反序列化一个json,Json中的一个字段是一个字符串,但我需要在字节数组PFB中读取相同的Bean和主类
public class Serialization implements Serializable{
private static final long serialVersionUID = 5894318390213780082L;
private String name = null;
@JsonDeserialize(using = StringtoByteArray.class)
private byte[] pass = null;
//getter setter
}
public class StringtoByteArray extends JsonDeserializer<byte []> {
@Override
public byte[] deserialize(JsonParser jsonParser, DeserializationContext deserializationContext)
throws IOException, JsonProcessingException {
return (jsonParser.getBinaryValue());
}
}
public class App
{
public static void main(String[] args) throws JsonGenerationException, JsonMappingException, IOException {
Serialization sr = new Serialization();
ObjectMapper mapper = new ObjectMapper();
sr = mapper.readValue(new File("D:\\check.json"), Serialization.class);
System.out.println("sr values ::" +sr.toString());
mapper.writeValue(new File("c:\\user.json"), sr);
}
}
My json 我的json
{
"name": "AD",
"pass": "pp"
}
At the time of Deserialize getting Exception in thread "main" com.fasterxml.jackson.databind.JsonMappingException: Failed to decode VALUE_STRING as base64 (MIME-NO-LINEFEEDS): Illegal character '"' (code 0x22) in base64 content Kindly suggest 在反序列化时在线程“main”中获取异常时com.fasterxml.jackson.databind.JsonMappingException:无法将VALUE_STRING解码为base64(MIME-NO-LINEFEEDS):base64内容中的非法字符“”(代码0x22)请提示
如果使用Java 8:在我的反序列化实现中,我需要返回
return (Base64.getEncoder().encode(jsonParser.getText().getBytes()))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.