本文整理了Java中com.fasterxml.jackson.databind.node.NullNode
类的一些代码示例,展示了NullNode
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。NullNode
类的具体详情如下:
包路径:com.fasterxml.jackson.databind.node.NullNode
类名称:NullNode
[英]This singleton value class is used to contain explicit JSON null value.
[中]这个单例值类用于包含显式JSON空值。
代码示例来源:origin: opentripplanner/OpenTripPlanner
@Override
public boolean reload(boolean force, boolean preEvict) {
// "Reloading" does not make sense for memory-graph, but we want to support mixing in-memory and file-based graphs.
// Start up graph updaters and apply runtime configuration options
// TODO will the updaters be started repeatedly due to reload calls?
try {
// There is no on-disk set of files for this graph, so only check for embedded router-config JSON.
ObjectMapper mapper = new ObjectMapper();
JsonNode routerJsonConf;
if (router.graph.routerConfig == null) {
LOG.info("No embedded router config available");
routerJsonConf = NullNode.getInstance();
} else {
routerJsonConf = mapper.readTree(router.graph.routerConfig);
}
router.startup(routerJsonConf);
return true;
} catch (IOException e) {
LOG.error("Can't startup graph: error with embed config (" + router.graph.routerConfig
+ ")", e);
return false;
}
}
代码示例来源:origin: marklogic/java-client-api
.addVariable("myInteger", (int) 31)
.addVariable("myDecimal", (double) 1.0471975511966)
.addVariableAs("myJsonObject", new ObjectMapper().createObjectNode().put("foo", "v1").putNull("testNull"))
.addVariableAs("myNull", (String) null)
.addVariableAs("myJsonArray", new ObjectMapper().createArrayNode().add(1).add(2).add(3));
System.out.println(new ObjectMapper().createObjectNode().nullNode().toString());
EvalResultIterator evr = evl.eval();
this.validateReturnTypes(evr);
代码示例来源:origin: net.thisptr/jackson-jq
} else if (accessHead instanceof ResolvedIndexFieldAccess) {
final ResolvedIndexFieldAccess access = (ResolvedIndexFieldAccess) accessHead;
if (in.isNull()) {
if (!creative)
return NullNode.getInstance();
final ArrayNode result = mapper.createArrayNode();
for (final long index : access.indices()) {
if (index < 0)
throw new JsonQueryException("Out of bounds negative array index");
while (index >= result.size())
result.add(NullNode.getInstance());
result.set((int) index, mutate(mapper, NullNode.getInstance(), accessTail, mutation, creative));
value = NullNode.getInstance();
final JsonNode newvalue = mutate(mapper, value, accessTail, mutation, creative);
tmp.add(NullNode.getInstance());
return NullNode.getInstance();
result.set(key, mutate(mapper, NullNode.getInstance(), accessTail, mutation, creative));
JsonNode value = result.get(key);
if (value == null && creative)
value = NullNode.getInstance();
final JsonNode newvalue = mutate(mapper, value, accessTail, mutation, creative);
if (newvalue == null) {
final JsonNode newvalue = mutate(mapper, NullNode.getInstance(), accessTail, mutation, creative);
代码示例来源:origin: net.thisptr/jackson-jq
@Override
public List<JsonNode> apply(final Scope scope, final JsonNode in) throws JsonQueryException {
final List<JsonNode> out = new ArrayList<>();
for (final Range range : ranges) {
if (in.isArray()) {
final Range r = range.over(in.size());
final ArrayNode array = scope.getObjectMapper().createArrayNode();
for (int index = (int) r.begin; index < (int) r.end; ++index)
array.add(in.get(index));
out.add(array);
} else if (in.isTextual()) {
final String _in = in.asText();
final Range r = range.over(UnicodeUtils.lengthUtf32(_in));
out.add(new TextNode(UnicodeUtils.substringUtf32(_in, (int) r.begin, (int) r.end)));
} else if (in.isNull()) {
out.add(NullNode.getInstance());
} else {
if (!permissive)
throw JsonQueryException.format("Cannot index %s with object", in.getNodeType());
}
}
return out;
}
代码示例来源:origin: com.hubspot.rosetta/RosettaCore
@Test
public void testAnnotatedSetterNullSerialization() {
assertThat(Rosetta.getMapper().valueToTree(bean).get("annotatedSetter"))
.isEqualTo(NullNode.getInstance());
}
代码示例来源:origin: rakam-io/rakam
public Object getJDBCValue(FieldType fieldType, JsonNode value, Connection conn)
throws SQLException {
if (value == NullNode.getInstance() || value == null) {
return null;
if (value.isArray()) {
FieldType arrayType = fieldType.getArrayElementType();
Object[] objects = new Object[value.size()];
for (int i = 0; i < value.size(); i++) {
objects[i] = getJDBCValue(arrayType, value.get(i), conn);
代码示例来源:origin: net.thisptr/jackson-jq
@Override
public List<JsonNode> apply(Scope scope, List<JsonQuery> args, JsonNode in) throws JsonQueryException {
Preconditions.checkInputArrayType("from_entries", in, JsonNodeType.OBJECT);
final ObjectNode out = scope.getObjectMapper().createObjectNode();
for (final JsonNode entry : in) {
JsonNode key = entry.get("key");
if (key == null)
key = entry.get("Key");
if (key == null)
key = entry.get("name");
if (key == null)
key = entry.get("Name");
if (key == null || !key.isTextual())
throw new JsonQueryException("input elements to from_entries() must be object and have 'key', 'Key' or 'Name' field");
JsonNode value = entry.get("value");
if (value == null)
value = entry.get("Value");
out.set(key.asText(), value == null ? NullNode.getInstance() : value);
}
return Collections.singletonList((JsonNode) out);
}
}
代码示例来源:origin: aws/aws-sdk-java
/**
* Evaluates a list projection expression in two steps.
* The left hand side (LHS) creates a JSON array of initial
* values.
* The right hand side (RHS) of a projection is the
* expression to project for each element in the JSON array
* created by the left hand side.
*
* @param jmesPathProjection JmesPath list projection type
* @param input Input json node against which evaluation is done
* @return Result of the projection evaluation
* @throws InvalidTypeException
*/
@Override
public JsonNode visit(JmesPathProjection jmesPathProjection, JsonNode input) throws InvalidTypeException {
JsonNode lhsResult = jmesPathProjection.getLhsExpr().accept(this, input);
if (lhsResult.isArray()) {
Iterator<JsonNode> elements = lhsResult.elements();
ArrayNode projectedArrayNode = ObjectMapperSingleton.getObjectMapper().createArrayNode();
while (elements.hasNext()) {
JsonNode projectedElement = jmesPathProjection.getProjectionExpr().accept(this, elements.next());
if (projectedElement != null) {
projectedArrayNode.add(projectedElement);
}
}
return projectedArrayNode;
}
return NullNode.getInstance();
}
代码示例来源:origin: docker-java/docker-java
@Override
public Ports deserialize(JsonParser jsonParser, DeserializationContext deserializationContext)
throws IOException, JsonProcessingException {
Ports out = new Ports();
ObjectCodec oc = jsonParser.getCodec();
JsonNode node = oc.readTree(jsonParser);
for (Iterator<Map.Entry<String, JsonNode>> it = node.fields(); it.hasNext();) {
Map.Entry<String, JsonNode> portNode = it.next();
JsonNode bindingsArray = portNode.getValue();
if (bindingsArray.equals(NullNode.getInstance())) {
out.bind(ExposedPort.parse(portNode.getKey()), null);
} else {
for (int i = 0; i < bindingsArray.size(); i++) {
JsonNode bindingNode = bindingsArray.get(i);
if (!bindingNode.equals(NullNode.getInstance())) {
String hostIp = bindingNode.get("HostIp").textValue();
String hostPort = bindingNode.get("HostPort").textValue();
out.bind(ExposedPort.parse(portNode.getKey()), new Binding(hostIp, hostPort));
}
}
}
}
return out;
}
}
代码示例来源:origin: docker-java/docker-java
@Override
public VolumeBinds deserialize(JsonParser jsonParser, DeserializationContext deserializationContext)
throws IOException, JsonProcessingException {
List<VolumeBind> binds = new ArrayList<VolumeBind>();
ObjectCodec oc = jsonParser.getCodec();
JsonNode node = oc.readTree(jsonParser);
for (Iterator<Map.Entry<String, JsonNode>> it = node.fields(); it.hasNext();) {
Map.Entry<String, JsonNode> field = it.next();
JsonNode value = field.getValue();
if (!value.equals(NullNode.getInstance())) {
if (!value.isTextual()) {
throw deserializationContext.mappingException("Expected path for '" + field.getKey()
+ "'in host but got '" + value + "'.");
}
VolumeBind bind = new VolumeBind(value.asText(), field.getKey());
binds.add(bind);
}
}
return new VolumeBinds(binds.toArray(new VolumeBind[binds.size()]));
}
}
代码示例来源:origin: com.hubspot.rosetta/RosettaCore
@Test
public void testOptionalFieldNullDeserialization() throws JsonProcessingException {
ObjectNode node = Rosetta.getMapper().createObjectNode();
node.put("optionalField", NullNode.getInstance());
StoredAsJsonBean bean = Rosetta.getMapper().treeToValue(node, StoredAsJsonBean.class);
assertThat(bean.getOptionalField()).isNotNull();
assertThat(bean.getOptionalField().isPresent()).isFalse();
}
代码示例来源:origin: software.amazon.awssdk/jmespath-java
public JsonNode visit(JmesPathFlatten flatten, JsonNode input) throws InvalidTypeException {
JsonNode flattenResult = flatten.getFlattenExpr().accept(this, input);
if (flattenResult.isArray()) {
Iterator<JsonNode> elements = flattenResult.elements();
ArrayNode flattenedArray = ObjectMapperSingleton.getObjectMapper().createArrayNode();
while (elements.hasNext()) {
JsonNode element = elements.next();
if (element != null) {
if (element.isArray()) {
Iterator<JsonNode> inner = element.iterator();
while (inner.hasNext()) {
JsonNode innerElement = inner.next();
if (innerElement != null) {
flattenedArray.add(innerElement);
flattenedArray.add(element);
return NullNode.getInstance();
代码示例来源:origin: embulk/embulk
@Deprecated
public ToString(com.google.common.base.Optional<JsonNode> option) throws JsonMappingException {
JsonNode node = option.or(NullNode.getInstance());
if (node.isTextual()) {
this.string = node.textValue();
} else if (node.isValueNode()) {
this.string = node.toString();
} else {
throw new JsonMappingException(String.format("Arrays and objects are invalid: '%s'", node));
}
}
代码示例来源:origin: aws/aws-sdk-java
/**
* Retrieves the value of the field node
*
* @param fieldNode JmesPath field type
* @param input Input json node whose value is
* retrieved
* @return Value of the input json node
*/
@Override
public JsonNode visit(JmesPathField fieldNode, JsonNode input) {
if (input.isObject()) {
//TODO : CamelCase will need to change at some point
return input.get(CamelCaseUtils.toCamelCase(fieldNode.getValue()));
}
return NullNode.getInstance();
}
代码示例来源:origin: docker-java/docker-java
@Override
public Links deserialize(final JsonParser jsonParser, final DeserializationContext deserializationContext)
throws IOException, JsonProcessingException {
final List<Link> binds = new ArrayList<Link>();
final ObjectCodec oc = jsonParser.getCodec();
final JsonNode node = oc.readTree(jsonParser);
for (final Iterator<JsonNode> it = node.elements(); it.hasNext();) {
final JsonNode element = it.next();
if (!element.equals(NullNode.getInstance())) {
binds.add(Link.parse(element.asText()));
}
}
return new Links(binds.toArray(new Link[0]));
}
}
代码示例来源:origin: net.thisptr/jackson-jq
@Override
public void match(final Scope scope, final JsonNode in, final Functional.Consumer<List<Pair<String, JsonNode>>> out, final Stack<Pair<String, JsonNode>> accumulate, final boolean emit) throws JsonQueryException {
if (!in.isArray() && !in.isNull())
throw JsonQueryTypeException.format("Cannot index %s with number", in.getNodeType());
for (int i = 0; i < matchers.size(); ++i) {
final PatternMatcher matcher = matchers.get(i);
final JsonNode item = in.get(i);
matcher.match(scope, item != null ? item : NullNode.getInstance(), out, accumulate, emit && i == matchers.size() - 1);
}
}
代码示例来源:origin: aws/aws-sdk-java
/**
* Evaluates the object projection expression.
* This will create a list of the values of the JSON
* object(lhs), and project the right hand side of the
* projection onto the list of values.
*
* @param valueProjection JmesPath value projection type
* @param input Input json node against which evaluation is done
* @return Result of the value projection evaluation
* @throws InvalidTypeException
*/
@Override
public JsonNode visit(JmesPathValueProjection valueProjection, JsonNode input) throws InvalidTypeException {
JsonNode projectedResult = valueProjection.getLhsExpr().accept(this, input);
if (projectedResult.isObject()) {
ArrayNode projectedArrayNode = ObjectMapperSingleton.getObjectMapper().createArrayNode();
Iterator<JsonNode> elements = projectedResult.elements();
while (elements.hasNext()) {
JsonNode projectedElement = valueProjection.getRhsExpr().accept(this, elements.next());
if (projectedElement != null) {
projectedArrayNode.add(projectedElement);
}
}
return projectedArrayNode;
}
return NullNode.getInstance();
}
代码示例来源:origin: io.macgyver.neorx/neorx
@Override
public Observable<JsonNode> call(JsonNode t1) {
JsonNode n = (JsonNode) t1.get(prop);
if (n==null) {
n = NullNode.getInstance();
}
return Observable.just(n);
}
};
代码示例来源:origin: opensourceBIM/BIMserver
public JsonNode toJson(Object object) throws IOException {
if (object instanceof SBase) {
SBase base = (SBase) object;
ObjectNode jsonObject = OBJECT_MAPPER.createObjectNode();
jsonObject.put("__type", base.getSClass().getSimpleName());
for (SField field : base.getSClass().getAllFields()) {
} else if (object instanceof Collection) {
Collection<?> collection = (Collection<?>) object;
ArrayNode jsonArray = OBJECT_MAPPER.createArrayNode();
for (Object value : collection) {
jsonArray.add(toJson(value));
return new TextNode(object.toString());
} else if (object == null) {
return NullNode.getInstance();
} else if (object instanceof byte[]) {
byte[] data = (byte[]) object;
代码示例来源:origin: docker-java/docker-java
@Override
public VolumeRW deserialize(JsonParser jsonParser, DeserializationContext deserializationContext)
throws IOException, JsonProcessingException {
ObjectCodec oc = jsonParser.getCodec();
JsonNode node = oc.readTree(jsonParser);
if (!node.equals(NullNode.getInstance())) {
Entry<String, JsonNode> field = node.fields().next();
String volume = field.getKey();
AccessMode accessMode = AccessMode.fromBoolean(field.getValue().asBoolean());
return new VolumeRW(new Volume(volume), accessMode);
} else {
return null;
}
}
}
内容来源于网络,如有侵权,请联系作者删除!