本文整理汇总了Java中com.fasterxml.jackson.databind.ser.std.StdSerializer类的典型用法代码示例。如果您正苦于以下问题:Java StdSerializer类的具体用法?Java StdSerializer怎么用?Java StdSerializer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
StdSerializer类属于com.fasterxml.jackson.databind.ser.std包,在下文中一共展示了StdSerializer类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: customJackson2HttpMessageConverter
import com.fasterxml.jackson.databind.ser.std.StdSerializer; //导入依赖的package包/类
/**
* Configure Jackson (enable Path to Json/String conversion)
*/
@Bean
public MappingJackson2HttpMessageConverter customJackson2HttpMessageConverter(MappingJackson2HttpMessageConverter converter) {
final ObjectMapper objectMapper = new ObjectMapper();
final SimpleModule sm = new SimpleModule();
sm.addSerializer(Path.class, new StdSerializer<Path>(Path.class) {
private static final long serialVersionUID = 8963132152002562810L;
@Override
public void serialize(Path value, JsonGenerator gen, SerializerProvider serializers)
throws IOException, JsonProcessingException {
gen.writeString(value.toString());
}
});
objectMapper.registerModule(sm);
converter.setObjectMapper(objectMapper);
return converter;
}
示例2: ObjectMapperResolver
import com.fasterxml.jackson.databind.ser.std.StdSerializer; //导入依赖的package包/类
public ObjectMapperResolver() {
mapper = new ObjectMapper();
SimpleModule module = new SimpleModule();
module.setDeserializerModifier(new BeanDeserializerModifier() {
@Override
public JsonDeserializer<Enum> modifyEnumDeserializer(DeserializationConfig config,
final JavaType type,
BeanDescription beanDesc,
final JsonDeserializer<?> deserializer) {
return new JsonDeserializer<Enum>() {
@Override
public Enum deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
Class<? extends Enum> rawClass = (Class<Enum<?>>) type.getRawClass();
return Enum.valueOf(rawClass, jp.getValueAsString().toUpperCase());
}
};
}
});
module.addSerializer(Enum.class, new StdSerializer<Enum>(Enum.class) {
@Override
public void serialize(Enum value, JsonGenerator jgen, SerializerProvider provider) throws IOException {
jgen.writeString(value.name().toLowerCase());
}
});
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
mapper.registerModule(module);
}
示例3: CommonModule
import com.fasterxml.jackson.databind.ser.std.StdSerializer; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public CommonModule() {
super("common", new Version(0, 1, 0, null, null, null));
setDeserializerModifier(new BeanDeserializerModifier() {
@Override
public JsonDeserializer<Enum> modifyEnumDeserializer(DeserializationConfig config,
final JavaType type,
BeanDescription beanDesc,
final JsonDeserializer<?> deserializer) {
return new JsonDeserializer<Enum>() {
@Override
public Enum deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
Class<? extends Enum> rawClass = (Class<Enum<?>>) type.getRawClass();
return Enum.valueOf(rawClass, jp.getValueAsString().toUpperCase());
}
};
}
});
addSerializer(Enum.class, new StdSerializer<Enum>(Enum.class) {
@Override
public void serialize(Enum value, JsonGenerator jgen, SerializerProvider provider) throws IOException {
jgen.writeString(value.name().toLowerCase());
}
});
addDeserializer(String.class, new RawValueDeserializer());
}
示例4: ObjectMapperResolver
import com.fasterxml.jackson.databind.ser.std.StdSerializer; //导入依赖的package包/类
public ObjectMapperResolver() {
mapper = new GraviteeMapper();
//because Permissions are represented as char[]
mapper.enable(SerializationFeature.WRITE_CHAR_ARRAYS_AS_JSON_ARRAYS);
// register filter provider
registerFilterProvider();
SimpleModule module = new SimpleModule();
module.setDeserializerModifier(new BeanDeserializerModifier() {
@Override
public JsonDeserializer<Enum> modifyEnumDeserializer(DeserializationConfig config,
final JavaType type,
BeanDescription beanDesc,
final JsonDeserializer<?> deserializer) {
return new JsonDeserializer<Enum>() {
@Override
public Enum deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
Class<? extends Enum> rawClass = (Class<Enum<?>>) type.getRawClass();
return Enum.valueOf(rawClass, jp.getValueAsString().toUpperCase());
}
};
}
});
module.addSerializer(Enum.class, new StdSerializer<Enum>(Enum.class) {
@Override
public void serialize(Enum value, JsonGenerator jgen, SerializerProvider provider) throws IOException {
jgen.writeString(value.name().toLowerCase());
}
});
mapper.registerModule(module);
}
示例5: registerEnumModule
import com.fasterxml.jackson.databind.ser.std.StdSerializer; //导入依赖的package包/类
/**
* Register Jackson module that maps enums as lowercase. Per http://stackoverflow.com/a/24173645.
*/
@SuppressWarnings("rawtypes")
private static void registerEnumModule(ObjectMapper mapper) {
SimpleModule module = new SimpleModule();
module.setDeserializerModifier(new BeanDeserializerModifier() {
@Override
public JsonDeserializer<Enum> modifyEnumDeserializer(DeserializationConfig config,
final JavaType type,
BeanDescription beanDesc,
final JsonDeserializer<?> deserializer) {
return new JsonDeserializer<Enum>() {
@Override
public Enum deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
@SuppressWarnings("unchecked") Class<? extends Enum> rawClass = (Class<Enum<?>>) type.getRawClass();
return Enum.valueOf(rawClass, jp.getValueAsString().toUpperCase());
}
};
}
});
module.addSerializer(Enum.class, new StdSerializer<Enum>(Enum.class) {
@Override
public void serialize(Enum value, JsonGenerator jgen, SerializerProvider provider) throws IOException {
jgen.writeString(value.name().toLowerCase());
}
});
mapper.registerModule(module);
}
示例6: CustomSerializer
import com.fasterxml.jackson.databind.ser.std.StdSerializer; //导入依赖的package包/类
protected CustomSerializer(StdSerializer<?> src) {
super(src);
}
示例7: MergerServiceImpl
import com.fasterxml.jackson.databind.ser.std.StdSerializer; //导入依赖的package包/类
@Inject
@SuppressWarnings({ "unchecked", "rawtypes" })
public MergerServiceImpl() {
JacksonXmlModule module = new JacksonXmlModule();
module.setDeserializerModifier(new BeanDeserializerModifier() {
@Override
public JsonDeserializer<Enum> modifyEnumDeserializer(
DeserializationConfig config, final JavaType type, BeanDescription beanDesc,
final JsonDeserializer<?> deserializer) {
return new JsonDeserializer<Enum>() {
@Override
public Enum deserialize(JsonParser jp, DeserializationContext ctxt)
throws IOException {
Class<? extends Enum> rawClass = (Class<Enum<?>>) type.getRawClass();
return Enum.valueOf(rawClass, jp.getValueAsString().toUpperCase());
}
};
}
});
module.addSerializer(Enum.class, new StdSerializer<Enum>(Enum.class) {
private static final long serialVersionUID = 4951133737173200158L;
@Override
public void serialize(Enum value, JsonGenerator jgen, SerializerProvider provider)
throws IOException {
jgen.writeString(StringUtils.capitalize(value.name().toLowerCase()));
}
});
// Extra non-JAXB annotations are needed to process abstract classes.
module.setMixInAnnotation(AbstractSourceT.class, AbstractMixIn.class);
mapper = new XmlMapper(module);
AnnotationIntrospector primary = new JacksonAnnotationIntrospector();
AnnotationIntrospector secondary = new JaxbAnnotationIntrospector(mapper.getTypeFactory());
AnnotationIntrospector pair = AnnotationIntrospectorPair.create(primary, secondary);
mapper.setAnnotationIntrospector(pair);
SimpleDateFormat sdf = new SimpleDateFormat(Utils.LONG_DATE_FORMAT);
mapper.setDateFormat(sdf);
// Serialization options
mapper.configure(SerializationFeature.INDENT_OUTPUT, true);
mapper.setSerializationInclusion(Include.NON_NULL);
}
示例8: setupModule
import com.fasterxml.jackson.databind.ser.std.StdSerializer; //导入依赖的package包/类
@Override
public void setupModule(final SetupContext context) {
context.addSerializers(new SimpleSerializers(Collections.<JsonSerializer<?>>singletonList(new StdSerializer<SpanWrapper>(SpanWrapper.class) {
@Override
public void serialize(SpanWrapper span, JsonGenerator gen, SerializerProvider serializers) throws IOException {
gen.writeStartObject();
Map<String, Object> parameters = null;
for (Map.Entry<String, Object> tag : span.getTags().entrySet()) {
if (tag.getKey().startsWith(SpanWrapper.INTERNAL_TAG_PREFIX)) {
continue;
}
if (tag.getKey().startsWith(PARAMETERS_PREFIX)) {
if (parameters == null) {
parameters = new HashMap<String, Object>();
}
parameters.put(tag.getKey().replace(PARAMETERS_PREFIX, ""), tag.getValue());
} else if (tag.getKey().equals(Tags.PEER_HOST_IPV4.getKey()) && tag.getValue() instanceof Integer) {
gen.writeStringField(IPV4_STRING, InetAddresses.fromInteger((Integer) tag.getValue()).getHostAddress());
gen.writeStringField("ip", InetAddresses.fromInteger((Integer) tag.getValue()).getHostAddress());
} else if (tag.getKey().equals(Tags.PEER_HOST_IPV6.getKey()) && tag.getValue() instanceof String) {
gen.writeStringField("ip", (String) tag.getValue());
} else {
gen.writeObjectField(tag.getKey(), tag.getValue());
}
}
if (parameters != null && !parameters.isEmpty()) {
gen.writeArrayFieldStart("parameters");
for (Map.Entry<String, Object> entry : parameters.entrySet()) {
gen.writeStartObject();
gen.writeObjectField("key", entry.getKey());
gen.writeObjectField("value", entry.getValue());
gen.writeEndObject();
}
gen.writeEndArray();
}
// always include error tag so we can have a successful/error filter in Kibana
if (!span.getTags().containsKey(Tags.ERROR.getKey())) {
gen.writeBooleanField("error", false);
}
gen.writeStringField("name", span.getOperationName());
gen.writeNumberField("duration_ms", span.getDurationMs());
final String timestamp = StringUtils.timestampAsIsoString(span.getStartTimestampMillis());
gen.writeStringField("@timestamp", timestamp);
gen.writeEndObject();
}
})));
}