类com.fasterxml.jackson.annotation.JsonSetter源码实例Demo

下面列出了怎么用com.fasterxml.jackson.annotation.JsonSetter的API类实例代码及写法,或者点击链接到github查看源代码。

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));
}
 
源代码2 项目: jbot   文件: Event.java
@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();
    }
}
 
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);
}
 
源代码4 项目: genie   文件: AgentConfigRequest.java
/**
 * 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;
}
 
源代码5 项目: lams   文件: ConfigOverrides.java
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;
}
 
源代码6 项目: spark-swagger   文件: ObjectProperty.java
@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);
            }
        }
    }
}
 
源代码7 项目: jackson-modules-base   文件: MergeWithNullTest.java
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);
}
 
源代码8 项目: jbot   文件: Event.java
@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();
    }
}
 
源代码9 项目: keycloak   文件: ResourceRepresentation.java
@Deprecated
@JsonSetter("uri")
public void setUri(String uri) {
    if (uri != null && !"".equalsIgnoreCase(uri.trim())) {
        this.uris = Collections.singleton(uri);
    }
}
 
源代码10 项目: ethsigner   文件: JsonRpcRequest.java
@JsonSetter("id")
public void setId(final JsonRpcRequestId id) {
  this.id = id;
}
 
源代码11 项目: ethsigner   文件: JsonRpcRequest.java
@JsonSetter("params")
public void setParams(final Object params) {
  this.params = params;
}
 
@JsonSetter("mowed_ts")
public void setMowedTimestamp (long mowed_ts_)
{
    mowedTimestamp = mowed_ts_;
}
 
源代码13 项目: algoliasearch-client-java-2   文件: SearchResult.java
@JsonSetter
public SearchResult<T> setProcessingTimeMS(Long processingTimeMS) {
  this.processingTimeMS = processingTimeMS;
  return this;
}
 
源代码14 项目: syncope   文件: JPAJSONUPlainAttr.java
@JsonSetter("membership")
public void setMembership(final String membership) {
    this.membership = membership;
}
 
@JsonSetter("device")
public void setDevice (String device_)
{
    device = device_;
}
 
源代码16 项目: spring-boot-samples   文件: WeatherEntry.java
@JsonSetter("dt")
public void setTimestamp(long unixTime) {
	this.timestamp = Instant.ofEpochMilli(unixTime * 1000);
}
 
源代码17 项目: Bats   文件: DrillStatsTable.java
@JsonSetter ("column")
public void setName(SchemaPath name) {
  this.name = name;
}
 
源代码18 项目: rocket-chat-rest-client   文件: Message.java
@JsonSetter("alias")
public void setUsernameAlias(String alias) {
    this.alias = alias;
}
 
源代码19 项目: Bats   文件: DrillStatsTable.java
@JsonSetter ("rowcount")
public void setCount(long count) {
  this.count = count;
}
 
源代码20 项目: Bats   文件: DrillStatsTable.java
@JsonSetter ("nonnullrowcount")
public void setNonNullCount(long nonNullCount) {
  this.nonNullCount = nonNullCount;
}
 
@JsonSetter("EnMin")
public void setEndMinute (int endMinute)
{
    this.endMinute = endMinute;
}
 
源代码22 项目: Bats   文件: DrillStatsTable.java
@JsonSetter ("avgwidth")
public void setAvgWidth(double width) { this.width = width; }
 
源代码23 项目: web3j   文件: WalletFile.java
@JsonSetter("Crypto") // older wallet files may have this attribute name
public void setCryptoV1(Crypto crypto) {
    setCrypto(crypto);
}
 
源代码24 项目: besu   文件: GraphQLJsonRequest.java
@JsonSetter
public void setOperationName(final String operationName) {
  this.operationName = operationName;
}
 
源代码25 项目: besu   文件: GraphQLJsonRequest.java
@JsonSetter
public void setVariables(final Map<String, Object> variables) {
  this.variables = variables;
}
 
源代码26 项目: allure2   文件: HistoryTrendItem.java
@JsonSetter("statistic")
public HistoryTrendItem setStatistic(final Statistic statistic) {
    this.data = statistic;
    return this;
}
 
源代码27 项目: mobi   文件: EntityNames.java
@JsonSetter("names")
public void setNames(Set<String> names) {
    this.names = names;
}
 
源代码28 项目: rocket-chat-rest-client   文件: Room.java
@JsonSetter("msgs")
public void setMessageCount(int count) {
    this.msgCount = count;
}
 
源代码29 项目: rocket-chat-rest-client   文件: ServerInfo.java
@JsonSetter("build")
public void setBuildInfo(ServerBuildInfo info) {
    this.buildInfo = info;
}
 
源代码30 项目: Knowage-Server   文件: DossierTemplate.java
@JsonSetter("REPORT")
public void setReports(List<Report> reports) {
	this.reports = reports;
}
 
 类方法
 同包方法