下面列出了com.fasterxml.jackson.annotation.JsonGetter#com.fasterxml.jackson.annotation.JsonUnwrapped 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
public void propertyField(JFieldVar field, JDefinedClass clazz, String propertyName, JsonNode propertyNode) {
propertyName = propertyName.equals("deprecatedAllowOrigin") ? "allowOrigin" : propertyName;
super.propertyField(field, clazz, propertyName, propertyNode);
if (propertyNode.hasNonNull(IS_INTERFACE_FIELD)) {
field.annotate(JsonUnwrapped.class);
// todo: fix me, this won't work if a type has several fields using interfaces
String interfaceFQN = propertyNode.get(EXISTING_JAVA_TYPE_FIELD).asText();
// create interface if we haven't done it yet
try {
final JDefinedClass fieldInterface = clazz._interface(interfaceFQN.substring(interfaceFQN.lastIndexOf('.') + 1));
fieldInterface._extends(Serializable.class);
} catch (JClassAlreadyExistsException e) {
throw new RuntimeException(e);
}
annotateIfNotDone(clazz, ClassWithInterfaceFieldsDeserializer.class);
}
}
/**
* The {@link Color} to display on the sidebar next to the {@link Attachment}.
*
* @return an {@link Optional} containing a {@link Color}
* @see Color
*/
@Value.Default
@Nullable
@JsonUnwrapped
public Color color() {
return null;
}
/**
* The {@link Author} for this {@link Attachment}. It is displayed in a small grayed-out section at the top
* before the main {@link Attachment} body.
*
* @return an {@link Optional} containing the {@link Author}
*/
@Value.Default
@Nullable
@JsonUnwrapped
public Author author() {
return null;
}
/**
* The {@link Title} for this {@link Attachment}. It is displayed as larger, bold text near the top before the main
* {@link Attachment} body.
*
* @return an {@link Optional} containing the {@link Title}
*/
@Value.Default
@Nullable
@JsonUnwrapped
public Title title() {
return null;
}
/**
* The {@link Footer} for this {@link Attachment}. This will appear below the body of the main message
* {@link Attachment} in smaller, grayed-out text.
*
* @return an {@link Optional} containing the {@link Footer}
*/
@Value.Default
@Nullable
@JsonUnwrapped
public Footer footer() {
return null;
}
private void addFieldToMap(Field field, ObjectContext objectContext,
Map<Field, ObjectContext> fieldContextMap, Set<Type> unwrappedTypes,
SchemaPropertyContext context) {
if (objectContext.isApplicable(field, context)) {
if (field.getAnnotation(JsonUnwrapped.class) != null) {
fieldContextMap.putAll(getUnwrappedFieldsMap(field, objectContext, unwrappedTypes,
context));
} else {
fieldContextMap.put(field, objectContext);
}
}
}
@JsonUnwrapped
@Nullable
DataSpec getDataSpec();
@JsonUnwrapped
@Nullable
DataSpec getDataSpec();
@Override
@JsonUnwrapped
@JsonIgnoreProperties("message")
public Object getLogEvent() {
return super.getLogEvent();
}
/**
* @return the data
*/
@JsonUnwrapped
public T getData() {
return data;
}
/**
* @param data the data to set
*/
@JsonUnwrapped
public void setData(T data) {
this.data = data;
}
@JsonUnwrapped
public User getUserConfig() {
return userConfig;
}
@JsonUnwrapped
public Value getValue() {
return value;
}
@JsonUnwrapped
public Resources<T> getNested() {
return this.nested;
}
@JsonUnwrapped
public T getContent() {
return content;
}
@JsonProperty("department")
@JsonUnwrapped
public List<Department> getDepartments() {
return departments;
}
@JsonInclude(NON_EMPTY)
@JsonUnwrapped
public Resources<EmbeddedWrapper> getEmbeddedResources() {
return new Resources(embedded);
}
@JsonUnwrapped
@XmlAnyElement
public T getContent() {
return content;
}
private static Optional<PropertyInfo> processProperty( RebindConfiguration configuration, TreeLogger logger, JacksonTypeOracle
typeOracle, PropertyAccessors propertyAccessors, BeanInfo beanInfo, boolean samePackage ) throws UnableToCompleteException {
boolean getterAutoDetected = isGetterAutoDetected( configuration, propertyAccessors, beanInfo );
boolean setterAutoDetected = isSetterAutoDetected( configuration, propertyAccessors, beanInfo );
boolean fieldAutoDetected = isFieldAutoDetected( configuration, propertyAccessors, beanInfo );
if ( !getterAutoDetected && !setterAutoDetected && !fieldAutoDetected && !propertyAccessors.getParameter().isPresent() ) {
// none of the field have been auto-detected, we ignore the field
return Optional.absent();
}
final String propertyName = propertyAccessors.getPropertyName();
final JType type = findType( logger, propertyAccessors, typeOracle, getterAutoDetected, setterAutoDetected, fieldAutoDetected );
PropertyInfoBuilder builder = new PropertyInfoBuilder( propertyName, type );
builder.setIgnored( isPropertyIgnored( configuration, propertyAccessors, beanInfo, type, propertyName ) );
if ( builder.isIgnored() ) {
return Optional.of( builder.build() );
}
Optional<JsonProperty> jsonProperty = propertyAccessors.getAnnotation( JsonProperty.class );
builder.setRequired( jsonProperty.isPresent() && jsonProperty.get().required() );
Optional<JsonManagedReference> jsonManagedReference = propertyAccessors.getAnnotation( JsonManagedReference.class );
builder.setManagedReference( Optional.fromNullable( jsonManagedReference.isPresent() ? jsonManagedReference.get()
.value() : null ) );
Optional<JsonBackReference> jsonBackReference = propertyAccessors.getAnnotation( JsonBackReference.class );
builder.setBackReference( Optional.fromNullable( jsonBackReference.isPresent() ? jsonBackReference.get().value() : null ) );
if ( !builder.getBackReference().isPresent() ) {
determineGetter( propertyAccessors, samePackage, getterAutoDetected, fieldAutoDetected, builder );
Optional<JsonRawValue> jsonRawValue = propertyAccessors.getAnnotation( JsonRawValue.class );
builder.setRawValue( jsonRawValue.isPresent() && jsonRawValue.get().value() );
}
determineSetter( propertyAccessors, samePackage, setterAutoDetected, fieldAutoDetected, builder );
Optional<JsonValue> jsonValue = propertyAccessors.getAnnotation( JsonValue.class );
if ( jsonValue.isPresent() && jsonValue.get().value() && builder.getGetterAccessor().isPresent() && builder.getGetterAccessor()
.get().getMethod().isPresent() ) {
builder.setValue( true );
}
Optional<JsonAnyGetter> jsonAnyGetter = propertyAccessors.getAnnotation( JsonAnyGetter.class );
if ( jsonAnyGetter.isPresent() && builder.getGetterAccessor().isPresent() && builder.getGetterAccessor().get().getMethod()
.isPresent() ) {
builder.setAnyGetter( true );
}
Optional<JsonAnySetter> jsonAnySetter = propertyAccessors.getAnnotation( JsonAnySetter.class );
if ( jsonAnySetter.isPresent() && builder.getSetterAccessor().isPresent() && builder.getSetterAccessor().get().getMethod()
.isPresent() && builder.getSetterAccessor().get().getMethod().get().getParameterTypes().length == 2 ) {
builder.setAnySetter( true );
}
Optional<JsonUnwrapped> jsonUnwrapped = propertyAccessors.getAnnotation( JsonUnwrapped.class );
if ( jsonUnwrapped.isPresent() && jsonUnwrapped.get().enabled() ) {
builder.setUnwrapped( true );
}
processBeanAnnotation( logger, typeOracle, configuration, type, propertyAccessors, builder );
builder.setFormat( propertyAccessors.getAnnotation( JsonFormat.class ) );
Optional<JsonInclude> jsonInclude = propertyAccessors.getAnnotation( JsonInclude.class );
if ( jsonInclude.isPresent() ) {
builder.setInclude( Optional.of( jsonInclude.get().value() ) );
} else {
builder.setInclude( beanInfo.getInclude() );
}
Optional<JsonIgnoreProperties> jsonIgnoreProperties = propertyAccessors.getAnnotation( JsonIgnoreProperties.class );
if ( jsonIgnoreProperties.isPresent() ) {
builder.setIgnoreUnknown( Optional.of( jsonIgnoreProperties.get().ignoreUnknown() ) );
if ( null != jsonIgnoreProperties.get().value() && jsonIgnoreProperties.get().value().length > 0 ) {
builder.setIgnoredProperties( Optional.of( jsonIgnoreProperties.get().value() ) );
}
}
return Optional.of( builder.build() );
}
@JsonUnwrapped
UnconfiguredTargetNode getUnconfiguredTargetNode();
@JsonUnwrapped
@JsonGetter
public Map<String, List<ScriptProviderMetadata>> getProviders() {
return providers;
}
@Override
@JsonUnwrapped
@JsonSerialize(as = LogEvent.class)
public LogEvent getLogEvent() {
return super.getLogEvent();
}
@JsonUnwrapped
public Object getLogEvent() {
return logEvent;
}
@Override
@JsonUnwrapped
@JsonSerialize(as = LogEvent.class)
public LogEvent getLogEvent() {
return super.getLogEvent();
}