Java Code Examples for com.fasterxml.jackson.annotation.JsonInclude.Include#ALWAYS
The following examples show how to use
com.fasterxml.jackson.annotation.JsonInclude.Include#ALWAYS .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JsonViewSerializer.java From json-view with GNU General Public License v3.0 | 5 votes |
boolean valueAllowed(AccessibleProperty property, Object value, Class cls) { Include defaultInclude = serializerProvider.getConfig() == null ? Include.ALWAYS : serializerProvider.getConfig().getSerializationInclusion(); JsonInclude jsonInclude = getAnnotation(property, JsonInclude.class); JsonSerialize jsonSerialize = getAnnotation(cls, JsonSerialize.class); // Make sure local annotations win over global ones if(jsonInclude != null && jsonInclude.value() == Include.NON_NULL && value == null) { return false; } return value != null || (defaultInclude == Include.ALWAYS && jsonSerialize == null) || (jsonSerialize != null && jsonSerialize.include() == Inclusion.ALWAYS); }
Example 2
Source File: JsonMapper.java From springcloud-idempotent-starter with GNU General Public License v3.0 | 4 votes |
/** * 创建只输出非Null且非Empty(如List.isEmpty)的属性到Json字符串的Mapper,建议在外部接口中使用. */ public static JsonMapper alwaysMapper() { return new JsonMapper(Include.ALWAYS); }
Example 3
Source File: JsonMapper.java From onetwo with Apache License 2.0 | 4 votes |
public static JsonMapper defaultMapper(){ JsonMapper jsonm = new JsonMapper(Include.ALWAYS); return jsonm; }
Example 4
Source File: JacksonXmlMapper.java From onetwo with Apache License 2.0 | 4 votes |
public static JacksonXmlMapper defaultMapper(){ JacksonXmlMapper jsonm = new JacksonXmlMapper(Include.ALWAYS); return jsonm; }
Example 5
Source File: RosettaAnnotationIntrospector.java From Rosetta with Apache License 2.0 | 4 votes |
@Override public Include findSerializationInclusion(Annotated a, Include defValue) { return Include.ALWAYS; }
Example 6
Source File: RosettaAnnotationIntrospector.java From Rosetta with Apache License 2.0 | 4 votes |
@Override public Include findSerializationInclusionForContent(Annotated a, Include defValue) { return Include.ALWAYS; }
Example 7
Source File: MessageSerializer.java From jackson-datatype-protobuf with Apache License 2.0 | 4 votes |
@Override public void serialize( MessageOrBuilder message, JsonGenerator generator, SerializerProvider serializerProvider ) throws IOException { generator.writeStartObject(); boolean proto3 = message.getDescriptorForType().getFile().getSyntax() == Syntax.PROTO3; Include include = serializerProvider.getConfig().getDefaultPropertyInclusion().getValueInclusion(); boolean writeDefaultValues = proto3 && include != Include.NON_DEFAULT; boolean writeEmptyCollections = include != Include.NON_DEFAULT && include != Include.NON_EMPTY; PropertyNamingStrategyBase namingStrategy = new PropertyNamingStrategyWrapper(serializerProvider.getConfig().getPropertyNamingStrategy()); Descriptor descriptor = message.getDescriptorForType(); List<FieldDescriptor> fields = new ArrayList<>(descriptor.getFields()); if (message instanceof ExtendableMessageOrBuilder<?>) { for (ExtensionInfo extensionInfo : config.extensionRegistry().getExtensionsByDescriptor(descriptor)) { fields.add(extensionInfo.descriptor); } } for (FieldDescriptor field : fields) { if (field.isRepeated()) { List<?> valueList = (List<?>) message.getField(field); if (!valueList.isEmpty() || writeEmptyCollections) { if (field.isMapField()) { generator.writeFieldName(namingStrategy.translate(field.getName())); writeMap(field, valueList, generator, serializerProvider); } else if (valueList.size() == 1 && writeSingleElementArraysUnwrapped(serializerProvider)) { generator.writeFieldName(namingStrategy.translate(field.getName())); writeValue(field, valueList.get(0), generator, serializerProvider); } else { generator.writeArrayFieldStart(namingStrategy.translate(field.getName())); for (Object subValue : valueList) { writeValue(field, subValue, generator, serializerProvider); } generator.writeEndArray(); } } } else if (message.hasField(field) || (writeDefaultValues && !supportsFieldPresence(field) && field.getContainingOneof() == null)) { generator.writeFieldName(namingStrategy.translate(field.getName())); writeValue(field, message.getField(field), generator, serializerProvider); } else if (include == Include.ALWAYS && field.getContainingOneof() == null) { generator.writeFieldName(namingStrategy.translate(field.getName())); generator.writeNull(); } } generator.writeEndObject(); }
Example 8
Source File: BuckFixSpec.java From buck with Apache License 2.0 | 4 votes |
/** Get a mapping of log short names to paths for those logs. */ @JsonProperty @JsonInclude(Include.ALWAYS) public abstract ImmutableMap<String, Optional<Path>> getLogs();
Example 9
Source File: JacksonBundle.java From base-framework with Apache License 2.0 | 2 votes |
/** * 创建不管任何值都序列化成json的ObjectMapper * * @return {@link JacksonBundle} */ public static JacksonBundle alwaysMapper() { return new JacksonBundle(Include.ALWAYS); }