当前位置: 首页>>代码示例>>Java>>正文


Java NullNode.instance方法代码示例

本文整理汇总了Java中com.fasterxml.jackson.databind.node.NullNode.instance方法的典型用法代码示例。如果您正苦于以下问题:Java NullNode.instance方法的具体用法?Java NullNode.instance怎么用?Java NullNode.instance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.fasterxml.jackson.databind.node.NullNode的用法示例。


在下文中一共展示了NullNode.instance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: toValueNode

import com.fasterxml.jackson.databind.node.NullNode; //导入方法依赖的package包/类
@Deprecated
public static ValueNode toValueNode(Object value) {

	if (value == null)
		return NullNode.instance;
	if (value instanceof ValueNode)
		return (ValueNode) value;
	if (value instanceof Boolean)
		return BooleanNode.valueOf((boolean) value);
	else if (value instanceof Integer)
		return IntNode.valueOf((int) value);
	else if (value instanceof Long)
		return LongNode.valueOf((long) value);
	else if (value instanceof Double)
		return DoubleNode.valueOf((double) value);
	else if (value instanceof Float)
		return FloatNode.valueOf((float) value);

	return TextNode.valueOf(value.toString());
}
 
开发者ID:spacedog-io,项目名称:spacedog-server,代码行数:21,代码来源:Json8.java

示例2: toValueNode

import com.fasterxml.jackson.databind.node.NullNode; //导入方法依赖的package包/类
public static ValueNode toValueNode(Object value) {

		if (value == null)
			return NullNode.instance;
		if (value instanceof ValueNode)
			return (ValueNode) value;
		if (value instanceof Boolean)
			return BooleanNode.valueOf((boolean) value);
		else if (value instanceof Integer)
			return IntNode.valueOf((int) value);
		else if (value instanceof Long)
			return LongNode.valueOf((long) value);
		else if (value instanceof Double)
			return DoubleNode.valueOf((double) value);
		else if (value instanceof Float)
			return FloatNode.valueOf((float) value);

		return TextNode.valueOf(value.toString());
	}
 
开发者ID:spacedog-io,项目名称:spacedog-server,代码行数:20,代码来源:Json7.java

示例3: _bindAsTree

import com.fasterxml.jackson.databind.node.NullNode; //导入方法依赖的package包/类
protected JsonNode _bindAsTree(JsonParser paramJsonParser)
{
  JsonToken localJsonToken = _initForReading(paramJsonParser);
  Object localObject;
  if ((localJsonToken == JsonToken.VALUE_NULL) || (localJsonToken == JsonToken.END_ARRAY) || (localJsonToken == JsonToken.END_OBJECT))
  {
    localObject = NullNode.instance;
  }
  else
  {
    DefaultDeserializationContext localDefaultDeserializationContext = createDeserializationContext(paramJsonParser, this._config);
    JsonDeserializer localJsonDeserializer = _findRootDeserializer(localDefaultDeserializationContext, JSON_NODE_TYPE);
    if (this._unwrapRoot)
      localObject = (JsonNode)_unwrapAndDeserialize(paramJsonParser, localDefaultDeserializationContext, JSON_NODE_TYPE, localJsonDeserializer);
    else
      localObject = (JsonNode)localJsonDeserializer.deserialize(paramJsonParser, localDefaultDeserializationContext);
  }
  paramJsonParser.clearCurrentToken();
  return localObject;
}
 
开发者ID:mmmsplay10,项目名称:QuizUpWinner,代码行数:21,代码来源:ObjectReader.java

示例4: getValue

import com.fasterxml.jackson.databind.node.NullNode; //导入方法依赖的package包/类
@Override
public Iterator<JsonNode> getValue(JsonNode payload, List<Integer> context) {
	return new Iterator<JsonNode>() {
		
		private int count = 0;
		
		@Override
		public boolean hasNext() {
			return count < nbIterations;
		}

		@Override
		public JsonNode next() {
			count++;
			return NullNode.instance;
		}
	};
}
 
开发者ID:fpoulin,项目名称:json-shapeshifter,代码行数:19,代码来源:ArrayConstantBinding.java

示例5: _bindAsTree

import com.fasterxml.jackson.databind.node.NullNode; //导入方法依赖的package包/类
protected JsonNode _bindAsTree(JsonParser jp)
    throws IOException, JsonParseException, JsonMappingException
{
    JsonNode result;
    JsonToken t = _initForReading(jp);
    if (t == JsonToken.VALUE_NULL || t == JsonToken.END_ARRAY || t == JsonToken.END_OBJECT) {
        result = NullNode.instance;
    } else {
        DeserializationContext ctxt = createDeserializationContext(jp, _config);
        JsonDeserializer<Object> deser = _findRootDeserializer(ctxt, JSON_NODE_TYPE);
        if (_unwrapRoot) {
            result = (JsonNode) _unwrapAndDeserialize(jp, ctxt, JSON_NODE_TYPE, deser);
        } else {
            result = (JsonNode) deser.deserialize(jp, ctxt);
        }
    }
    // Need to consume the token too
    jp.clearCurrentToken();
    return result;
}
 
开发者ID:joyplus,项目名称:joyplus-tv,代码行数:21,代码来源:ObjectReader.java

示例6: toJson

import com.fasterxml.jackson.databind.node.NullNode; //导入方法依赖的package包/类
/**
 * Serialize an object to {@link JsonNode}, with a custom class loader.
 * 
 * @param obj
 * @param classLoader
 * @return
 * @since 0.6.2
 */
public static JsonNode toJson(Object obj, ClassLoader classLoader) {
    ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
    if (classLoader != null) {
        Thread.currentThread().setContextClassLoader(classLoader);
    }
    try {
        if (obj == null) {
            return NullNode.instance;
        }
        ObjectMapper mapper = poolMapper.borrowObject();
        if (mapper != null) {
            try {
                return mapper.valueToTree(obj);
            } finally {
                poolMapper.returnObject(mapper);
            }
        }
        throw new SerializationException("No ObjectMapper instance avaialble!");
    } catch (Exception e) {
        throw e instanceof SerializationException ? (SerializationException) e
                : new SerializationException(e);
    } finally {
        Thread.currentThread().setContextClassLoader(oldClassLoader);
    }
}
 
开发者ID:DDTH,项目名称:ddth-commons,代码行数:34,代码来源:SerializationUtils.java

示例7: readJson

import com.fasterxml.jackson.databind.node.NullNode; //导入方法依赖的package包/类
/**
 * Read a JSON string and parse to {@link JsonNode} instance, with a custom class loader.
 * 
 * @param source
 * @param classLoader
 * @return
 * @since 0.6.2
 */
public static JsonNode readJson(String source, ClassLoader classLoader) {
    ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
    if (classLoader != null) {
        Thread.currentThread().setContextClassLoader(classLoader);
    }
    try {
        if (StringUtils.isBlank(source)) {
            return NullNode.instance;
        }
        ObjectMapper mapper = poolMapper.borrowObject();
        if (mapper != null) {
            try {
                return mapper.readTree(source);
            } finally {
                poolMapper.returnObject(mapper);
            }
        }
        throw new SerializationException("No ObjectMapper instance avaialble!");
    } catch (Exception e) {
        throw e instanceof SerializationException ? (SerializationException) e
                : new SerializationException(e);
    } finally {
        Thread.currentThread().setContextClassLoader(oldClassLoader);
    }
}
 
开发者ID:DDTH,项目名称:ddth-commons,代码行数:34,代码来源:SerializationUtils.java

示例8: putMetadata

import com.fasterxml.jackson.databind.node.NullNode; //导入方法依赖的package包/类
@Override
public void putMetadata(String namespace, String key, Object object) {
    checkAlreadyEmitted();
    validateNotNull(namespace);
    validateNotNull(key);
    if (null == object) {
        object = NullNode.instance;
    }
    metadata.computeIfAbsent(namespace, (n) -> {
        return new ConcurrentHashMap<String, Object>();
    }).put(key, object);
}
 
开发者ID:aws,项目名称:aws-xray-sdk-java,代码行数:13,代码来源:EntityImpl.java

示例9: primitiveToJson

import com.fasterxml.jackson.databind.node.NullNode; //导入方法依赖的package包/类
/**
 * Serialize primtive values to JSON .
 */
static <T> JsonNode primitiveToJson(final T value, final TypeNode type) {
  final JsonNode result;
  // for BinaryTreeNode
  if (value == null) {
    return NullNode.instance;
  }

  switch (type.getValue()) {
    case BOOL:
      result = BooleanNode.valueOf((Boolean) value);
      break;
    case CHAR:
      result = TextNode.valueOf(value.toString());
      break;
    case STRING:
      result = TextNode.valueOf((String) value);
      break;
    case DOUBLE:
      result = DoubleNode.valueOf((Double) value);
      break;
    case INT:
      result = IntNode.valueOf((Integer) value);
      break;
    case LONG:
      result = LongNode.valueOf((Long) value);
      break;
    default:
      throw new IllegalArgumentException("Unrecognized primitive type: " + type);
  }
  return result;
}
 
开发者ID:algohub,项目名称:judge-engine,代码行数:35,代码来源:Serializer.java

示例10: parseData

import com.fasterxml.jackson.databind.node.NullNode; //导入方法依赖的package包/类
protected void parseData() {
    lock();
    try {
        dataJson = SerializationUtils.readJson(getData());
    } catch (Exception e) {
        dataJson = NullNode.instance;
    } finally {
        unlock();
    }
}
 
开发者ID:DDTH,项目名称:ddth-dao,代码行数:11,代码来源:BaseDataJsonFieldBo.java

示例11: serialize

import com.fasterxml.jackson.databind.node.NullNode; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 * @throws SerializationException
 */
@Override
public JsonNode serialize(Message message, ReadableSchemaRegistry registry)
		throws SerializationException {
	ObjectNode object = new ObjectNode(JsonNodeFactory.instance);

	for (Descriptors.FieldDescriptor field : descriptor.getFields()) {
		String propertyName = AutoSchema.PROTO_FIELD_CASE_FORMAT
				.to(AutoSchema.JSON_FIELD_CASE_FORMAT, field.getName());
		if (field.isRepeated()) {
			if (message.getRepeatedFieldCount(field) > 0) {
					ArrayNode array = serializeRepeatedField(message, field, registry);
					if (array.size() != 0) {
						object.put(propertyName, array);
					}
			}
		} else if (message.hasField(field)) {
			Object value = message.getField(field);
			JsonNode fieldNode = serializeValue(value, field, registry);
			if (!fieldNode.isNull()) {
				object.put(propertyName, fieldNode);
			}
		}
	}

	if (object.size() == 0) {
		return NullNode.instance;
	}

	return object;
}
 
开发者ID:turn,项目名称:shapeshifter,代码行数:35,代码来源:AutoSerializer.java

示例12: serialize

import com.fasterxml.jackson.databind.node.NullNode; //导入方法依赖的package包/类
/** 
 * @param object the number of milliseconds since the Unix epoch
 */
@Override
public JsonNode serialize(Object object) {
	if (object == null) {
		return NullNode.instance;
	}
	Preconditions.checkArgument(object instanceof Long);
	Long millis = (Long) object;
	return new TextNode(ISO_8601.print(millis));
}
 
开发者ID:turn,项目名称:shapeshifter,代码行数:13,代码来源:DateTimeTransformer.java

示例13: serialize

import com.fasterxml.jackson.databind.node.NullNode; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 *
 * This variation allows for the inclusion of schemas for serializing
 * sub-objects that may appear in {@code message}. If no suitable schema
 * is found in the registry, a schema with default settings is generated
 * on the fly using {@link
 * SchemaSource#get(com.google.protobuf.Descriptors.Descriptor)}.
 *
 */
@Override
public JsonNode serialize(Message message, ReadableSchemaRegistry registry)
		throws SerializationException {
	ObjectNode object = new ObjectNode(JsonNodeFactory.instance);
	for (Map.Entry<String, String> constant : schema.getConstants().entrySet()) {
		object.put(constant.getKey(), constant.getValue());
	}
	for (Map.Entry<String, FieldDescriptor> fieldEntry : schema.getFields().entrySet()) {
		if (schema.getSkippedFields().contains(fieldEntry.getKey())) {
			continue;
		}
		FieldDescriptor field = fieldEntry.getValue();
		if (field.isRepeated()) {
			int count = message.getRepeatedFieldCount(field);
			if (count > 0) {
				if (schema.getMappings().containsKey(field.getName())) {
					ObjectNode objectNode = serializeMappedField(
							message, registry, field, count);
					if (objectNode.size() > 0) {
						object.put(schema.getPropertyName(field.getName()), objectNode);
					}
				} else {
					ArrayNode array = serializeRepeatedField(message, registry, field, count);
					if (array.size() > 0) {
						object.put(schema.getPropertyName(field.getName()), array);
					}
				}
			}
		} else if (message.hasField(field)) {
			Object value = message.getField(field);
			JsonNode fieldNode = serializeValue(value, field, registry);
			object.put(schema.getPropertyName(field.getName()), fieldNode);
		}
	}
	if (object.size() == 0) {
		return NullNode.instance;
	}
	return object;
}
 
开发者ID:turn,项目名称:shapeshifter,代码行数:50,代码来源:NamedSchemaSerializer.java

示例14: serialize

import com.fasterxml.jackson.databind.node.NullNode; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public JsonNode serialize(Message message, ReadableSchemaRegistry registry)
		throws SerializationException {
	ObjectNode object = new ObjectNode(JsonNodeFactory.instance);
	for (Map.Entry<String, String> constant : schema.getConstants().entrySet()) {
		object.put(constant.getKey(), constant.getValue());
	}
	for (Map.Entry<String, FieldDescriptor> fieldEntry : schema.getFields().entrySet()) {
		if (schema.getSkippedFields().contains(fieldEntry.getKey())) {
			continue;
		}
		FieldDescriptor field = fieldEntry.getValue();
		if (field.isRepeated()) {
			int count = message.getRepeatedFieldCount(field);
			if (count > 0) {
				if (schema.getMappings().containsKey(field.getName())) {
					ObjectNode objectNode = serializeMappedField(
							message, registry, field, count);
					if (objectNode.size() > 0) {
						object.put(schema.getPropertyName(field.getName()), objectNode);
					}
				} else {
					ArrayNode array = serializeRepeatedField(message, registry, field, count);
					if (array.size() > 0) {
						object.put(schema.getPropertyName(field.getName()), array);
					}
				}
			}
		} else if (message.hasField(field)) {
			Object value = message.getField(field);
			JsonNode fieldNode = serializeValue(value, field, registry);
			object.put(schema.getPropertyName(field.getName()), fieldNode);
		}
	}
	if (object.size() == 0) {
		return NullNode.instance;
	}
	return object;
}
 
开发者ID:turn,项目名称:shapeshifter,代码行数:43,代码来源:SchemaSerializer.java

示例15: from

import com.fasterxml.jackson.databind.node.NullNode; //导入方法依赖的package包/类
@Override
public JsonNode from(Object t) {
    try {
        return t == null ? NullNode.instance
                         : new ObjectMapper().readTree(t + "");
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:ChiralBehaviors,项目名称:Ultrastructure,代码行数:10,代码来源:PostgresJSONJacksonJsonNodeConverter.java


注:本文中的com.fasterxml.jackson.databind.node.NullNode.instance方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。