gu.sql2java.json.RawJsonDeserializer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sql2java-base Show documentation
Show all versions of sql2java-base Show documentation
sql2java common class package
The newest version!
package gu.sql2java.json;
import java.io.IOException;
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.ObjectMapper;
/**
* Deserializing JSON property as String with Jackson
* 实现将有{@code com.fasterxml.jackson.annotation.JsonRawValue}注解的
* 内容为JSON的String类型字段反序列化为String的反序列化器实现
* copy from 《Deserializing JSON property as String with Jackson》
*
*/
public class RawJsonDeserializer extends JsonDeserializer {
@Override
public String deserialize(JsonParser jp, DeserializationContext ctxt)
throws IOException, JsonProcessingException {
ObjectMapper mapper = (ObjectMapper) jp.getCodec();
JsonNode node = mapper.readTree(jp);
return mapper.writeValueAsString(node);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy