com.fasterxml.jackson.annotation.JsonSetter Java Examples

The following examples show how to use com.fasterxml.jackson.annotation.JsonSetter. 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: NullConversionsForContentTest.java    From jackson-modules-base with Apache License 2.0 6 votes vote down vote up
public void testNullsAsEmptyUsingDefaults() throws Exception
{
    final String JSON = aposToQuotes("{'values':[null]}");
    TypeReference<NullContentUndefined<List<Integer>>> listType = new TypeReference<NullContentUndefined<List<Integer>>>() { };

    // Let's see defaulting in action
    ObjectMapper mapper = afterburnerMapperBuilder()
            .changeDefaultNullHandling(n -> n.withContentNulls(Nulls.AS_EMPTY))
            .build();
    NullContentUndefined<List<Integer>> result = mapper.readValue(JSON, listType);
    assertEquals(1, result.values.size());
    assertEquals(Integer.valueOf(0), result.values.get(0));

    // or configured for type:
    mapper = afterburnerMapperBuilder()
            .withConfigOverride(List.class,
                    o -> o.setNullHandling(JsonSetter.Value.forContentNulls(Nulls.AS_EMPTY)))
            .build();
    result = mapper.readValue(JSON, listType);
    assertEquals(1, result.values.size());
    assertEquals(Integer.valueOf(0), result.values.get(0));
}
 
Example #2
Source File: ConfigOverrides.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
protected ConfigOverrides(Map<Class<?>, MutableConfigOverride> overrides,
        JsonInclude.Value defIncl,
        JsonSetter.Value defSetter,
        VisibilityChecker<?> defVisibility,
        Boolean defMergeable) {
    _overrides = overrides;
    _defaultInclusion = defIncl;
    _defaultSetterInfo = defSetter;
    _visibilityChecker = defVisibility;
    _defaultMergeable = defMergeable;
}
 
Example #3
Source File: AgentConfigRequest.java    From genie with Apache License 2.0 5 votes vote down vote up
/**
 * Set the directory where the agent should put the job working directory.
 *
 * @param requestedJobDirectoryLocation The location
 * @return The builder
 */
@JsonSetter
public Builder withRequestedJobDirectoryLocation(@Nullable final String requestedJobDirectoryLocation) {
    this.bRequestedJobDirectoryLocation = requestedJobDirectoryLocation == null
        ? null
        : new File(requestedJobDirectoryLocation);
    return this;
}
 
Example #4
Source File: MergeWithNullTest.java    From jackson-modules-base with Apache License 2.0 5 votes vote down vote up
public void testBeanMergingWithNullDefault() throws Exception
{
    // By default `null` should simply overwrite value
    ConfigDefault config = MAPPER.readerForUpdating(new ConfigDefault(5, 7))
            .readValue(aposToQuotes("{'loc':null}"));
    assertNotNull(config);
    assertNull(config.loc);

    // but it should be possible to override setting to, say, skip

    // First: via specific type override
    // important! We'll specify for value type to be merged
    ObjectMapper mapper = afterburnerMapperBuilder()
            .withConfigOverride(AB.class,
                    o -> o.setNullHandling(JsonSetter.Value.forValueNulls(Nulls.SKIP)))
            .build();
    config = mapper.readerForUpdating(new ConfigDefault(137, -3))
            .readValue(aposToQuotes("{'loc':null}"));
    assertNotNull(config.loc);
    assertEquals(137, config.loc.a);
    assertEquals(-3, config.loc.b);

    // Second: by global defaults
    mapper = afterburnerMapperBuilder()
            .changeDefaultNullHandling(n -> n.withValueNulls(Nulls.SKIP))
            .build();
    config = mapper.readerForUpdating(new ConfigDefault(12, 34))
            .readValue(aposToQuotes("{'loc':null}"));
    assertNotNull(config.loc);
    assertEquals(12, config.loc.a);
    assertEquals(34, config.loc.b);
}
 
Example #5
Source File: Event.java    From jbot with GNU General Public License v3.0 5 votes vote down vote up
@JsonSetter("channel")
public void setChannel(JsonNode jsonNode) {
    if (jsonNode.isObject()) {
        try {
            this.channel = new ObjectMapper().treeToValue(jsonNode, Channel.class);
        } catch (JsonProcessingException e) {
            logger.error("Error deserializing json: ", e);
        }
    } else if (jsonNode.isTextual()) {
        this.channelId = jsonNode.asText();
    }
}
 
Example #6
Source File: ResourceRepresentation.java    From keycloak with Apache License 2.0 5 votes vote down vote up
@Deprecated
@JsonSetter("uri")
public void setUri(String uri) {
    if (uri != null && !"".equalsIgnoreCase(uri.trim())) {
        this.uris = Collections.singleton(uri);
    }
}
 
Example #7
Source File: NullConversionsSkipTest.java    From jackson-modules-base with Apache License 2.0 5 votes vote down vote up
public void testSkipNullWithDefaults() throws Exception
{
    String json = aposToQuotes("{'value':null}");
    StringValue result = MAPPER.readValue(json, StringValue.class);
    assertNull(result.value);

    ObjectMapper mapper = afterburnerMapperBuilder()
            .withConfigOverride(String.class,
                     o -> o.setNullHandling(JsonSetter.Value.forValueNulls(Nulls.SKIP)))
            .build();
    result = mapper.readValue(json, StringValue.class);
    assertEquals("default", result.value);
}
 
Example #8
Source File: ObjectProperty.java    From spark-swagger with Apache License 2.0 5 votes vote down vote up
@JsonSetter("required")
public void setRequiredProperties(List<String> required) {
    if (properties != null) {
        for (String s : required) {
            Property p = properties.get(s);
            if (p != null) {
                p.setRequired(true);
            }
        }
    }
}
 
Example #9
Source File: Event.java    From jbot with GNU General Public License v3.0 5 votes vote down vote up
@JsonSetter("file")
public void setFile(JsonNode jsonNode) {
    if (jsonNode.isObject()) {
        try {
            this.file = new ObjectMapper().treeToValue(jsonNode, File.class);
        } catch (JsonProcessingException e) {
            logger.error("Error deserializing json: ", e);
        }
    } else if (jsonNode.isTextual()) {
        this.fileId = jsonNode.asText();
    }
}
 
Example #10
Source File: Configuration.java    From java with Apache License 2.0 4 votes vote down vote up
@JsonSetter
void setLastSavedView(String lastSavedView) {
    this.lastSavedView = lastSavedView;
}
 
Example #11
Source File: DeviceStateInformation.java    From iot-device-bosch-indego-controller with Apache License 2.0 4 votes vote down vote up
@JsonSetter("mapsvgcache_ts")
public void setMapSvgCacheTimestamp (long mapsvgcache_ts_)
{
    mapSvgCacheTimestamp = mapsvgcache_ts_;
}
 
Example #12
Source File: ClientImpl.java    From quarkus with Apache License 2.0 4 votes vote down vote up
@JsonSetter("app_version_code")
public void setVersionCode(String versionCode) {
    this.versionCode = versionCode;
}
 
Example #13
Source File: ServerInfo.java    From rocket-chat-rest-client with MIT License 4 votes vote down vote up
@JsonSetter("commit")
public ServerCommitInfo getCommitInfo() {
    return this.commitInfo;
}
 
Example #14
Source File: ClientContextImpl.java    From quarkus with Apache License 2.0 4 votes vote down vote up
@JsonSetter("client")
public void setImpl(ClientImpl impl) {
    this.impl = impl;
}
 
Example #15
Source File: ClientContextImpl.java    From quarkus with Apache License 2.0 4 votes vote down vote up
@JsonSetter("env")
public void setEnv(Map<String, String> env) {
    this.env = env;
}
 
Example #16
Source File: EnumTypeDefinition.java    From conjure with Apache License 2.0 4 votes vote down vote up
@JsonSetter(nulls = Nulls.FAIL, contentNulls = Nulls.FAIL)
List<EnumValueDefinition> values();
 
Example #17
Source File: JPAJSONLAPlainAttr.java    From syncope with Apache License 2.0 4 votes vote down vote up
@JsonSetter("schema")
public void setSchema(final String schema) {
    this.schema = schema;
}
 
Example #18
Source File: FactEntity.java    From act-platform with ISC License 4 votes vote down vote up
@JsonSetter("direction")
public FactObjectBinding setDirectionValue(int value) {
  this.direction = Direction.getValueMap().get(value);
  return this;
}
 
Example #19
Source File: Setting.java    From rocket-chat-rest-client with MIT License 4 votes vote down vote up
@JsonSetter("value")
public void setValue(Object value){
	this.value = value;
}
 
Example #20
Source File: TemplateMetadata.java    From azure-gradle-plugins with MIT License 4 votes vote down vote up
@JsonSetter
public void setName(String name) {
    this.name = name;
}
 
Example #21
Source File: DirectDebitEventsResponse.java    From pay-publicapi with MIT License 4 votes vote down vote up
@JsonSetter("last_page")
void setLastLink(Link link) {
    this.lastLink = link;
}
 
Example #22
Source File: TemplateMetadata.java    From azure-gradle-plugins with MIT License 4 votes vote down vote up
@JsonSetter
public void setUserPrompt(List<String> userPrompt) {
    this.userPrompt = userPrompt;
}
 
Example #23
Source File: ServerBuildInfo.java    From rocket-chat-rest-client with MIT License 4 votes vote down vote up
@JsonSetter("cpus")
public void setCPUCount(int cpus) {
    this.cpus = cpus;
}
 
Example #24
Source File: ResolveResult.java    From universal-resolver with Apache License 2.0 4 votes vote down vote up
@JsonSetter
public final void setDidDocument(DIDDocument didDocument) {

	this.didDocument = didDocument;
}
 
Example #25
Source File: Widget.java    From smartsheet-java-sdk with Apache License 2.0 4 votes vote down vote up
/**
 * Set the y-coordinate of widget's position on the sight.
 *
 * @param yPosition
 */
@JsonSetter("yPosition")
public Widget setYPosition(Integer yPosition) {
    this.yPosition = yPosition;
    return this;
}
 
Example #26
Source File: ResolveResult.java    From universal-resolver with Apache License 2.0 4 votes vote down vote up
@JsonSetter
public void setContent(Object content) {

	this.content = content;
}
 
Example #27
Source File: AggregateReportParameters.java    From sailfish-core with Apache License 2.0 4 votes vote down vote up
@JsonSetter
public void setTo(LocalDateTime to) {
	this.to = to;
}
 
Example #28
Source File: AggregateReportParameters.java    From sailfish-core with Apache License 2.0 4 votes vote down vote up
@JsonSetter
public void setFrom(LocalDateTime from) {
	this.from = from;
}
 
Example #29
Source File: Configuration.java    From java with Apache License 2.0 4 votes vote down vote up
@JsonSetter
void setDefaultView(String defaultView) {
    this.defaultView = defaultView;
}
 
Example #30
Source File: UnionTypeDefinition.java    From conjure with Apache License 2.0 4 votes vote down vote up
@JsonSetter(nulls = Nulls.FAIL, contentNulls = Nulls.FAIL)
Map<FieldName, FieldDefinition> union();