private void initAny() { final Method jsonAnyGetter = ClassUtils.findMethodWith(resourceClass, JsonAnyGetter.class); final Method jsonAnySetter = ClassUtils.findMethodWith(resourceClass, JsonAnySetter.class); if (absentAnySetter(jsonAnyGetter, jsonAnySetter)) { throw new InvalidResourceException( String.format("A resource %s has to have both methods annotated with @JsonAnySetter and @JsonAnyGetter", resourceClass.getCanonicalName())); } if (jsonAnyGetter != null) { anyFieldAccessor = new AnyResourceFieldAccessor() { @Override public Object getValue(Object resource, String name) { try { return jsonAnyGetter.invoke(resource, name); } catch (IllegalAccessException | InvocationTargetException e) { throw new ResourceException( String.format("Exception while reading %s.%s due to %s", resource, name, e.getMessage()), e); } } @Override public void setValue(Object resource, String name, Object fieldValue) { try { jsonAnySetter.invoke(resource, name, fieldValue); } catch (IllegalAccessException | InvocationTargetException e) { throw new ResourceException( String.format("Exception while writting %s.%s=%s due to %s", resource, name, fieldValue, e.getMessage()), e); } } }; } }
@JsonAnySetter public void setValue(String name, Object value) { if (this.properties == null) { this.properties = new HashMap<>(); } this.properties.put(name, value); }
@JsonAnySetter public void setProperty(String key, List<String> values){ if(CollectionUtils.isEmpty(values)){ removeProperty(key); } else { properties.put(key, values); } }
@JsonAnySetter public void setAdditionalProperty(String name, Object value) { this.additionalProperties.put(name, value); }
@JsonAnySetter abstract void add(String key, Object value);
@Override public void anySetter(JMethod setter) { setter.annotate(JsonAnySetter.class); }
@JsonAnySetter public void set(String name, String value) { properties.put( name, value ); }
@JsonAnySetter public void setAdditionalMap(String name, Object value) { additionalMap.put(name, value); }
@JsonAnySetter public void setAdditionalProperties(String name, Object value) { this.additionalProperties.put(name, value); }
@JsonAnySetter public void set(final String name, final Object value) { properties.put(name, value); }
@JsonAnySetter public void set(String key, Object value) { extras.put(key, value); }
@JsonAnySetter protected void setConfigParam(String name, Object value) { configuration.put(name, value); }