protected static void fromJson( String value, Set<String> fields, Map<String, ByteIterator> result) throws IOException { JsonNode json = MAPPER.readTree(value); boolean checkFields = fields != null && !fields.isEmpty(); for (Iterator<Map.Entry<String, JsonNode>> jsonFields = json.getFields(); jsonFields.hasNext(); /* increment in loop body */) { Map.Entry<String, JsonNode> jsonField = jsonFields.next(); String name = jsonField.getKey(); if (checkFields && !fields.contains(name)) { continue; } JsonNode jsonValue = jsonField.getValue(); if (jsonValue != null && !jsonValue.isNull()) { result.put(name, new StringByteIterator(jsonValue.asText())); } } }
throw new AvroRuntimeException("Field " + field + " not set and has no default value"); if (json.isNull() && (field.schema().getType() == Type.NULL || (field.schema().getType() == Type.UNION
if (byDefault != null && !byDefault.isNull()) { return applyDefaultValue(schemaNode, byDefault);
if (!fieldNode.isNull()) { String fieldValue = createSqlStringValue(fieldNode, colSize, sqlType); attributes.put(attributePrefix + ".args." + fieldCount + ".value", fieldValue);
if (!fieldNode.isNull()) { String fieldValue = fieldNode.asText(); if (colSize != null && fieldValue.length() > colSize) {
if (!fieldNode.isNull()) { String fieldValue = createSqlStringValue(fieldNode, colSize, sqlType); attributes.put(attributePrefix + ".args." + fieldCount + ".value", fieldValue);
if ( !node.isNull() )
return defaultValue.isBoolean(); case NULL: return defaultValue.isNull(); case ARRAY: if (!defaultValue.isArray())
} else if (jsonNode.isNull()) { return JsonProperties.NULL_VALUE; } else if (jsonNode.isBoolean()) {
@Test public void testJsonEmptyRPFormatter() throws Exception { WMFullResourcePlan fullRp = createRP("test_rp_1", null, null); formatter.showFullResourcePlan(out, fullRp); out.flush(); ObjectMapper objectMapper = new ObjectMapper(); JsonNode jsonTree = objectMapper.readTree(bos.toByteArray()); assertNotNull(jsonTree); assertTrue(jsonTree.isObject()); assertEquals("test_rp_1", jsonTree.get("name").asText()); assertTrue(jsonTree.get("parallelism").isNull()); assertTrue(jsonTree.get("defaultPool").isNull()); assertTrue(jsonTree.get("pools").isArray()); assertEquals(0, jsonTree.get("pools").size()); }
protected Object convertField(final JsonNode fieldNode, final String fieldName, final DataType desiredType, final boolean dropUnknown) throws IOException, MalformedRecordException { if (fieldNode == null || fieldNode.isNull()) { return null;
protected Object convertField(final JsonNode fieldNode, final String fieldName, final DataType desiredType, final boolean dropUnknown) throws IOException, MalformedRecordException { if (fieldNode == null || fieldNode.isNull()) { return null;
protected Object getRawNodeValue(final JsonNode fieldNode, final DataType dataType) throws IOException { if (fieldNode == null || fieldNode.isNull()) { return null;
switch(fieldType) { case NULL: if(!defaultJson.isNull()) { expectedVal = "null";
protected Object getRawNodeValue(final JsonNode fieldNode, final DataType dataType) throws IOException { if (fieldNode == null || fieldNode.isNull()) { return null;
private static void assertJsonEquals( String message, Object expected, JsonNode actual ) { if ( expected == null ) { assertTrue( message, actual == null || actual.isNull() ); } else if ( expected instanceof String ) { assertEquals( message, expected, actual.getTextValue() ); } else if ( expected instanceof Number ) { assertEquals( message, expected, actual.getNumberValue() ); } else { fail( message + " - unexpected type - " + expected ); } }
break; case NULL: if (!n.isNull()) throw new AvroTypeException("Non-null default value for null type: "+n); e.writeNull();
@Override public Object parseJson(JsonNode jsonNode) { /// For structs, they just return a list of object values if (jsonNode.isNull()) return null; List<Object> valList = new ArrayList<Object>(); for (int i = 0; i < fieldNames.size(); ++i) { String key = fieldNames.get(i); JsonNode valNode = jsonNode.get(key); InspectorHandle valHandle = handleList.get(i); Object valObj = valHandle.parseJson(valNode); valList.add(valObj); } return valList; }
@Override public Object parseJson(JsonNode jsonNode) { if (jsonNode.isNull()) return null; Map<String, Object> newMap = (Map<String, Object>) retInspector.create(); Iterator<String> keys = jsonNode.getFieldNames(); while (keys.hasNext()) { String key = keys.next(); JsonNode valNode = jsonNode.get(key); Object val = mapValHandle.parseJson(valNode); newMap.put(key, val); } return newMap; }
@Override public Object parseJson(JsonNode jsonNode) { if (jsonNode.isNull()) return null; List newList = (List) retInspector.create(0); Iterator<JsonNode> listNodes = jsonNode.getElements(); while (listNodes.hasNext()) { JsonNode elemNode = listNodes.next(); if (elemNode != null) { Object elemObj = elemHandle.parseJson(elemNode); newList.add(elemObj); } else { newList.add(null); } } return newList; }