Search in sources :

Example 1 with FloatNode

use of com.fasterxml.jackson.databind.node.FloatNode in project swagger-core by swagger-api.

the class PropertyDeserializer method getEnum.

private static List<String> getEnum(JsonNode node, PropertyBuilder.PropertyId type) {
    final List<String> result = new ArrayList<String>();
    JsonNode detailNode = getDetailNode(node, type);
    if (detailNode != null) {
        ArrayNode an = (ArrayNode) detailNode;
        for (JsonNode child : an) {
            if (child instanceof TextNode || child instanceof NumericNode || child instanceof IntNode || child instanceof LongNode || child instanceof DoubleNode || child instanceof FloatNode) {
                result.add(child.asText());
            }
        }
    }
    return result.isEmpty() ? null : result;
}
Also used : IntNode(com.fasterxml.jackson.databind.node.IntNode) ArrayList(java.util.ArrayList) FloatNode(com.fasterxml.jackson.databind.node.FloatNode) DoubleNode(com.fasterxml.jackson.databind.node.DoubleNode) JsonNode(com.fasterxml.jackson.databind.JsonNode) TextNode(com.fasterxml.jackson.databind.node.TextNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) NumericNode(com.fasterxml.jackson.databind.node.NumericNode) LongNode(com.fasterxml.jackson.databind.node.LongNode)

Example 2 with FloatNode

use of com.fasterxml.jackson.databind.node.FloatNode in project symja_android_library by axkr.

the class ExpressionJSONConvert method importExpressionJSONRecursive.

public static IExpr importExpressionJSONRecursive(JsonNode node) {
    if (node instanceof ArrayNode) {
        ArrayNode arrayNode = (ArrayNode) node;
        Iterator<JsonNode> iter = arrayNode.elements();
        IASTAppendable ast;
        if (iter.hasNext()) {
            JsonNode next = iter.next();
            IExpr temp = importExpressionJSONRecursive(next);
            if (temp.isPresent()) {
                ast = F.ast(temp, arrayNode.size() - 1);
                while (iter.hasNext()) {
                    next = iter.next();
                    temp = importExpressionJSONRecursive(next);
                    if (temp.isPresent()) {
                        ast.append(temp);
                    }
                }
                return ast;
            }
        }
        return F.NIL;
    } else if (node instanceof ObjectNode) {
        IASTAppendable list = F.ListAlloc();
        ObjectNode objectNode = (ObjectNode) node;
        Iterator<Entry<String, JsonNode>> iter = objectNode.fields();
        while (iter.hasNext()) {
            Entry<String, JsonNode> next = iter.next();
            IExpr temp = importExpressionJSONRecursive(next.getValue());
            if (temp.isPresent()) {
                list.append(F.Rule(F.$str(next.getKey()), temp));
            }
        }
        return list;
    } else if (node instanceof ValueNode) {
        ValueNode valueNode = (ValueNode) node;
        if (valueNode instanceof NumericNode) {
            if (valueNode instanceof DoubleNode) {
                return F.num(valueNode.doubleValue());
            } else if (valueNode instanceof FloatNode) {
                return F.num(valueNode.doubleValue());
            } else if (valueNode instanceof IntNode) {
                return F.ZZ(valueNode.intValue());
            } else if (valueNode instanceof LongNode) {
                return F.ZZ(valueNode.longValue());
            } else if (valueNode instanceof ShortNode) {
                return F.ZZ(valueNode.intValue());
            } else if (valueNode instanceof BigIntegerNode) {
                return F.ZZ(valueNode.bigIntegerValue());
            } else if (valueNode instanceof DecimalNode) {
                return F.num(new Apfloat(valueNode.decimalValue()));
            }
        }
        if (valueNode instanceof BooleanNode) {
            return valueNode.booleanValue() ? S.True : S.False;
        } else if (valueNode instanceof NullNode) {
            return S.Null;
        } else if (valueNode instanceof TextNode) {
            String symbolName = valueNode.textValue();
            if (symbolName.length() > 1 && symbolName.charAt(0) == '\'' && symbolName.charAt(symbolName.length() - 1) == '\'') {
                return F.$str(symbolName.substring(1, symbolName.length() - 1));
            }
            if (Scanner.isIdentifier(symbolName)) {
                return F.symbol(symbolName);
            }
            return F.$str(symbolName);
        }
        return F.$str(valueNode.toString());
    }
    return F.NIL;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) FloatNode(com.fasterxml.jackson.databind.node.FloatNode) DoubleNode(com.fasterxml.jackson.databind.node.DoubleNode) JsonNode(com.fasterxml.jackson.databind.JsonNode) BigIntegerNode(com.fasterxml.jackson.databind.node.BigIntegerNode) TextNode(com.fasterxml.jackson.databind.node.TextNode) NumericNode(com.fasterxml.jackson.databind.node.NumericNode) LongNode(com.fasterxml.jackson.databind.node.LongNode) BooleanNode(com.fasterxml.jackson.databind.node.BooleanNode) Apfloat(org.apfloat.Apfloat) ShortNode(com.fasterxml.jackson.databind.node.ShortNode) Entry(java.util.Map.Entry) IntNode(com.fasterxml.jackson.databind.node.IntNode) IASTAppendable(org.matheclipse.core.interfaces.IASTAppendable) Iterator(java.util.Iterator) ValueNode(com.fasterxml.jackson.databind.node.ValueNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) IExpr(org.matheclipse.core.interfaces.IExpr) DecimalNode(com.fasterxml.jackson.databind.node.DecimalNode) NullNode(com.fasterxml.jackson.databind.node.NullNode)

Example 3 with FloatNode

use of com.fasterxml.jackson.databind.node.FloatNode in project symja_android_library by axkr.

the class JSONConvert method importJSONRecursive.

public static IExpr importJSONRecursive(JsonNode node) {
    if (node instanceof ArrayNode) {
        ArrayNode arrayNode = (ArrayNode) node;
        Iterator<JsonNode> iter = arrayNode.elements();
        IASTAppendable list = F.ListAlloc(arrayNode.size());
        while (iter.hasNext()) {
            JsonNode next = iter.next();
            IExpr temp = importJSONRecursive(next);
            if (temp.isPresent()) {
                list.append(temp);
            }
        }
        return list;
    } else if (node instanceof ObjectNode) {
        IASTAppendable list = F.ListAlloc();
        ObjectNode objectNode = (ObjectNode) node;
        Iterator<Entry<String, JsonNode>> iter = objectNode.fields();
        while (iter.hasNext()) {
            Entry<String, JsonNode> next = iter.next();
            IExpr temp = importJSONRecursive(next.getValue());
            if (temp.isPresent()) {
                list.append(F.Rule(F.$str(next.getKey()), temp));
            }
        }
        return list;
    } else if (node instanceof ValueNode) {
        ValueNode valueNode = (ValueNode) node;
        if (valueNode instanceof NumericNode) {
            if (valueNode instanceof DoubleNode) {
                return F.num(valueNode.doubleValue());
            } else if (valueNode instanceof FloatNode) {
                return F.num(valueNode.doubleValue());
            } else if (valueNode instanceof IntNode) {
                return F.ZZ(valueNode.intValue());
            } else if (valueNode instanceof LongNode) {
                return F.ZZ(valueNode.longValue());
            } else if (valueNode instanceof ShortNode) {
                return F.ZZ(valueNode.intValue());
            } else if (valueNode instanceof BigIntegerNode) {
                return F.ZZ(valueNode.bigIntegerValue());
            } else if (valueNode instanceof DecimalNode) {
                return F.num(new Apfloat(valueNode.decimalValue()));
            }
        }
        if (valueNode instanceof BooleanNode) {
            return valueNode.booleanValue() ? S.True : S.False;
        } else if (valueNode instanceof NullNode) {
            return S.Null;
        } else if (valueNode instanceof TextNode) {
            return F.$str(valueNode.textValue());
        }
        return F.$str(valueNode.toString());
    }
    return F.NIL;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) FloatNode(com.fasterxml.jackson.databind.node.FloatNode) DoubleNode(com.fasterxml.jackson.databind.node.DoubleNode) JsonNode(com.fasterxml.jackson.databind.JsonNode) BigIntegerNode(com.fasterxml.jackson.databind.node.BigIntegerNode) TextNode(com.fasterxml.jackson.databind.node.TextNode) NumericNode(com.fasterxml.jackson.databind.node.NumericNode) LongNode(com.fasterxml.jackson.databind.node.LongNode) BooleanNode(com.fasterxml.jackson.databind.node.BooleanNode) Apfloat(org.apfloat.Apfloat) ShortNode(com.fasterxml.jackson.databind.node.ShortNode) Entry(java.util.Map.Entry) IntNode(com.fasterxml.jackson.databind.node.IntNode) IASTAppendable(org.matheclipse.core.interfaces.IASTAppendable) Iterator(java.util.Iterator) ValueNode(com.fasterxml.jackson.databind.node.ValueNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) IExpr(org.matheclipse.core.interfaces.IExpr) DecimalNode(com.fasterxml.jackson.databind.node.DecimalNode) NullNode(com.fasterxml.jackson.databind.node.NullNode)

Example 4 with FloatNode

use of com.fasterxml.jackson.databind.node.FloatNode in project BIMserver by opensourceBIM.

the class JsonConverter method toJson.

// public void toJson(Object object, ObjectMapper objectMapper) throws IOException, SerializerException {
// if (object instanceof SBase) {
// SBase base = (SBase) object;
// out.beginObject();
// out.name("__type");
// out.value(base.getSClass().getSimpleName());
// for (SField field : base.getSClass().getAllFields()) {
// out.name(field.getName());
// toJson(base.sGet(field), out);
// }
// out.endObject();
// } else if (object instanceof Collection) {
// Collection<?> collection = (Collection<?>) object;
// out.beginArray();
// for (Object value : collection) {
// toJson(value, out);
// }
// out.endArray();
// } else if (object instanceof Date) {
// out.value(((Date) object).getTime());
// } else if (object instanceof DataHandler) {
// DataHandler dataHandler = (DataHandler) object;
// ByteArrayOutputStream baos = new ByteArrayOutputStream();
// if (dataHandler.getDataSource() instanceof CacheStoringEmfSerializerDataSource) {
// CacheStoringEmfSerializerDataSource cacheStoringEmfSerializerDataSource = (CacheStoringEmfSerializerDataSource) dataHandler.getDataSource();
// cacheStoringEmfSerializerDataSource.writeToOutputStream(baos, null);
// out.value(new String(Base64.encodeBase64(baos.toByteArray()), Charsets.UTF_8));
// } else {
// InputStream inputStream = dataHandler.getInputStream();
// IOUtils.copy(inputStream, baos);
// out.value(new String(Base64.encodeBase64(baos.toByteArray()), Charsets.UTF_8));
// }
// } else if (object instanceof byte[]) {
// byte[] data = (byte[]) object;
// out.value(new String(Base64.encodeBase64(data), Charsets.UTF_8));
// } else if (object instanceof String) {
// out.value((String) object);
// } else if (object instanceof Number) {
// out.value((Number) object);
// } else if (object instanceof Enum) {
// out.value(object.toString());
// } else if (object instanceof Boolean) {
// out.value((Boolean) object);
// } else if (object == null) {
// out.nullValue();
// } else {
// throw new UnsupportedOperationException(object.toString());
// }
// }
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()) {
            jsonObject.set(field.getName(), toJson(base.sGet(field)));
        }
        return jsonObject;
    } else if (object instanceof Collection) {
        Collection<?> collection = (Collection<?>) object;
        ArrayNode jsonArray = OBJECT_MAPPER.createArrayNode();
        for (Object value : collection) {
            jsonArray.add(toJson(value));
        }
        return jsonArray;
    } else if (object instanceof Date) {
        return new LongNode(((Date) object).getTime());
    } else if (object instanceof DataHandler) {
        DataHandler dataHandler = (DataHandler) object;
        InputStream inputStream = dataHandler.getInputStream();
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        IOUtils.copy(inputStream, out);
        return new TextNode(new String(Base64.encodeBase64(out.toByteArray()), Charsets.UTF_8));
    } else if (object instanceof Boolean) {
        return BooleanNode.valueOf((Boolean) object);
    } else if (object instanceof String) {
        return new TextNode((String) object);
    } else if (object instanceof Long) {
        return new LongNode((Long) object);
    } else if (object instanceof UUID) {
        return new TextNode(((UUID) object).toString());
    } else if (object instanceof Integer) {
        return new IntNode((Integer) object);
    } else if (object instanceof Double) {
        return new DoubleNode((Double) object);
    } else if (object instanceof Float) {
        return new FloatNode((Float) object);
    } else if (object instanceof Enum) {
        return new TextNode(object.toString());
    } else if (object == null) {
        return NullNode.getInstance();
    } else if (object instanceof byte[]) {
        byte[] data = (byte[]) object;
        return new TextNode(new String(Base64.encodeBase64(data), Charsets.UTF_8));
    }
    throw new UnsupportedOperationException(object.getClass().getName());
}
Also used : FloatNode(com.fasterxml.jackson.databind.node.FloatNode) SField(org.bimserver.shared.meta.SField) DataHandler(javax.activation.DataHandler) LongNode(com.fasterxml.jackson.databind.node.LongNode) IntNode(com.fasterxml.jackson.databind.node.IntNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) UUID(java.util.UUID) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) InputStream(java.io.InputStream) DoubleNode(com.fasterxml.jackson.databind.node.DoubleNode) TextNode(com.fasterxml.jackson.databind.node.TextNode) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Date(java.util.Date) SBase(org.bimserver.shared.meta.SBase) Collection(java.util.Collection)

Aggregations

ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)4 DoubleNode (com.fasterxml.jackson.databind.node.DoubleNode)4 FloatNode (com.fasterxml.jackson.databind.node.FloatNode)4 IntNode (com.fasterxml.jackson.databind.node.IntNode)4 LongNode (com.fasterxml.jackson.databind.node.LongNode)4 TextNode (com.fasterxml.jackson.databind.node.TextNode)4 JsonNode (com.fasterxml.jackson.databind.JsonNode)3 NumericNode (com.fasterxml.jackson.databind.node.NumericNode)3 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)3 BigIntegerNode (com.fasterxml.jackson.databind.node.BigIntegerNode)2 BooleanNode (com.fasterxml.jackson.databind.node.BooleanNode)2 DecimalNode (com.fasterxml.jackson.databind.node.DecimalNode)2 NullNode (com.fasterxml.jackson.databind.node.NullNode)2 ShortNode (com.fasterxml.jackson.databind.node.ShortNode)2 ValueNode (com.fasterxml.jackson.databind.node.ValueNode)2 Iterator (java.util.Iterator)2 Entry (java.util.Map.Entry)2 Apfloat (org.apfloat.Apfloat)2 IASTAppendable (org.matheclipse.core.interfaces.IASTAppendable)2 IExpr (org.matheclipse.core.interfaces.IExpr)2