@Override public Boolean asBoolean() { return !data.isBoolean() ? null : data.asBoolean(); }
@Nullable private Object valueNode(JsonNode jsonNode) { if (jsonNode.isInt()) { return jsonNode.asInt(); } else if (jsonNode.isLong()) { return jsonNode.asLong(); } else if (jsonNode.isIntegralNumber()) { return jsonNode.asLong(); } else if (jsonNode.isFloatingPointNumber()) { return jsonNode.asDouble(); } else if (jsonNode.isBoolean()) { return jsonNode.asBoolean(); } else if (jsonNode.isNull()) { return null; } else { return jsonNode.asText(); } }
private Object toValue(JsonNode node) throws IOException { if (node.isTextual()) { return node.asText(); } else if (node.isNumber()) { return node.numberValue(); } else if (node.isBoolean()) { return node.asBoolean(); } else if (node.isBinary()) { return node.binaryValue(); } else { throw new IllegalStateException("Unexpected range bound value: " + node); } } }
@Override public AckArgs deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException { List<Object> args = new ArrayList<Object>(); AckArgs result = new AckArgs(args); ObjectMapper mapper = (ObjectMapper) jp.getCodec(); JsonNode root = mapper.readTree(jp); AckCallback<?> callback = currentAckClass.get(); Iterator<JsonNode> iter = root.iterator(); int i = 0; while (iter.hasNext()) { Object val; Class<?> clazz = callback.getResultClass(); if (callback instanceof MultiTypeAckCallback) { MultiTypeAckCallback multiTypeAckCallback = (MultiTypeAckCallback) callback; clazz = multiTypeAckCallback.getResultClasses()[i]; } JsonNode arg = iter.next(); if (arg.isTextual() || arg.isBoolean()) { clazz = Object.class; } val = mapper.treeToValue(arg, clazz); args.add(val); i++; } return result; }
@Override public Object getField(String fieldName) { JsonNode fn = jn.get(fieldName); if (fn.isContainerNode()) { AtomicInteger idx = new AtomicInteger(0); List<Field> fields = Lists.newArrayList(fn.fieldNames()) .stream() .map(f -> new Field(f, idx.getAndIncrement())) .collect(Collectors.toList()); return new GenericJsonRecord(fields, fn); } else if (fn.isBoolean()) { return fn.asBoolean(); } else if (fn.isInt()) { return fn.asInt(); } else if (fn.isFloatingPointNumber()) { return fn.asDouble(); } else if (fn.isDouble()) { return fn.asDouble(); } else { return fn.asText(); } } }
@Override public VolumesRW deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException { List<VolumeRW> volumesRW = new ArrayList<VolumeRW>(); 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.isBoolean()) { throw deserializationContext.mappingException("Expected access mode for '" + field.getKey() + "' in host but got '" + value + "'."); } VolumeRW bind = new VolumeRW(new Volume(field.getKey()), AccessMode.fromBoolean(value.asBoolean())); volumesRW.add(bind); } } return new VolumesRW(volumesRW.toArray(new VolumeRW[volumesRW.size()])); } }
public static Object toObject(final JsonNode node) { if (node.isArray()) { return new ArrayList() { { for (JsonNode jsonNodes : node) { add(toObject(jsonNodes)); } } }; } else if (node.isObject()) { return new HashMap() { { for (Iterator<Map.Entry<String, JsonNode>> i = node.fields(); i.hasNext();) { Map.Entry<String, JsonNode> next = i.next(); Object o = toObject(next.getValue()); put(next.getKey(), o); } } }; } else if (node.isBoolean()) { return node.booleanValue(); } else if (node.isNull()) { return null; } else { return node.asText(); } }
private Object convert(final JsonNode value) { if (value == null || value.isNull()) return null; if (value.isBoolean()) { return value.booleanValue(); } else if (value.isValueNode()) { return value.asText(); } else if (value.isArray()) { return (Iterable) () -> new Iterator() { private Iterator<JsonNode> iterator = value.iterator(); @Override public boolean hasNext() { return iterator.hasNext(); } @Override public Object next() { return convert(iterator.next()); } @Override public void remove() { } }; } else { return new JsonMap(value); } } }
boolean success = true; final List<String> errors = new ArrayList<>(); if (successNode.isBoolean()) { success = successNode.asBoolean(); final JsonNode errorsNode = node.path("errors");
JsonNode resultNode = ((JsonNode) base).get(property.toString()); if (resultNode != null && resultNode.isValueNode()) { if (resultNode.isBoolean()) { result = resultNode.asBoolean(); } else if (resultNode.isLong()) {
private byte[] extractJNodeValue(final JsonNode n){ if (n.isBoolean()){ //boolean return clientService.toBytes(n.asBoolean()); }else if(n.isNumber()){ if(n.isIntegralNumber()){ //interpret as Long return clientService.toBytes(n.asLong()); }else{ //interpret as Double return clientService.toBytes(n.asDouble()); } }else{ //if all else fails, interpret as String return clientService.toBytes(n.asText()); } }
return defaultValue.isNumber(); case BOOLEAN: return defaultValue.isBoolean(); case NULL: return defaultValue.isNull();
return json.asInt(); else if ( json.isNumber() || json.isBoolean() ) { return BigInteger.valueOf( json.asLong() );
@Override public PathDetail deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException { JsonNode pathDetail = jp.readValueAsTree(); if (pathDetail.size() != 3) throw new JsonParseException(jp, "PathDetail array must have exactly 3 entries but was " + pathDetail.size()); JsonNode from = pathDetail.get(0); JsonNode to = pathDetail.get(1); JsonNode val = pathDetail.get(2); PathDetail pd; if (val.isBoolean()) pd = new PathDetail(val.asBoolean()); else if (val.isLong()) pd = new PathDetail(val.asLong()); else if (val.isInt()) pd = new PathDetail(val.asInt()); else if (val.isDouble()) pd = new PathDetail(val.asDouble()); else if (val.isTextual()) pd = new PathDetail(val.asText()); else throw new JsonParseException(jp, "Unsupported type of PathDetail value " + pathDetail.getNodeType().name()); pd.setFirst(from.asInt()); pd.setLast(to.asInt()); return pd; } }
if (valueType == ValueType.BOOLEAN && value.isBoolean()) { return ValueReference.of(value.booleanValue()); } else if (valueType == ValueType.DOUBLE && value.isDouble()) {
} else if (jsonNode.isNull()) { return JsonProperties.NULL_VALUE; } else if (jsonNode.isBoolean()) { return jsonNode.asBoolean(); } else if (jsonNode.isInt()) {
else if ( json.isNumber() || json.isBoolean() ) { return BigInteger.valueOf( json.asLong() );
} else if (e.isBoolean()) { return e.asBoolean(); } else if (e.isInt()) {
return (new Text(value.textValue())); case BOOLEAN: return (new BooleanWritable(value.isBoolean() ? value.booleanValue() : Boolean.valueOf(value.textValue()))); default: throw new SerDeException("Unknown type: " + typeInfo.getTypeName());
public JDefinedClass apply(String nodeName, JsonNode node, JsonNode parent, JDefinedClass jclass, Schema schema) { if (node != null && node.isBoolean() && node.asBoolean() == false) {