All Downloads are FREE. Search and download functionalities are using the official Maven repository.

gu.sql2java.json.RawJsonDeserializer Maven / Gradle / Ivy

There is a newer version: 5.3.2
Show 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