Java Code Examples for com.fasterxml.jackson.core.JsonGenerator#writeNullField()
The following examples show how to use
com.fasterxml.jackson.core.JsonGenerator#writeNullField() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TransactionGraphLabelsIOProvider.java From constellation with Apache License 2.0 | 6 votes |
@Override public void writeObject(final Attribute attr, final int elementId, final JsonGenerator jsonGenerator, final GraphReadMethods graph, final GraphByteWriter byteWriter, final boolean verbose) throws IOException { if (verbose || !graph.isDefaultValue(attr.getId(), elementId)) { final GraphLabels graphLabels = graph.getObjectValue(attr.getId(), elementId); if (graphLabels == null) { jsonGenerator.writeNullField(attr.getName()); } else { jsonGenerator.writeArrayFieldStart(attr.getName()); for (GraphLabel graphLabel : graphLabels.getLabels()) { jsonGenerator.writeStartObject(); jsonGenerator.writeStringField(ATTRIBUTE_NAME, graphLabel.getAttributeName()); final ConstellationColor color = graphLabel.getColor(); jsonGenerator.writeObjectFieldStart(COLOR); ColorIOProvider.writeColorObject(color, jsonGenerator); jsonGenerator.writeEndObject(); jsonGenerator.writeNumberField(RADIUS, graphLabel.getSize()); jsonGenerator.writeEndObject(); } jsonGenerator.writeEndArray(); } } }
Example 2
Source File: Bean70ABindMap.java From kripton with Apache License 2.0 | 6 votes |
@Override public int serializeOnJacksonAsString(Bean70A object, JsonGenerator jacksonSerializer) throws Exception { jacksonSerializer.writeStartObject(); int fieldCount=0; // Serialized Field: // field valueBean (mapped with "valueBean") if (object.valueBean!=null) { fieldCount++; jacksonSerializer.writeFieldName("valueBean"); if (bean70ABindMap.serializeOnJacksonAsString(object.valueBean, jacksonSerializer)==0) { jacksonSerializer.writeNullField("valueBean"); } } // field valueString (mapped with "valueString") if (object.valueString!=null) { fieldCount++; jacksonSerializer.writeStringField("valueString", object.valueString); } jacksonSerializer.writeEndObject(); return fieldCount; }
Example 3
Source File: TableEntitySerializer.java From azure-storage-android with Apache License 2.0 | 6 votes |
private static void writeJsonProperty(JsonGenerator generator, Entry<String, EntityProperty> prop) throws JsonGenerationException, IOException { EdmType edmType = prop.getValue().getEdmType(); if (prop.getValue().getIsNull()) { generator.writeNullField(prop.getKey()); } else if (edmType == EdmType.BOOLEAN) { generator.writeBooleanField(prop.getKey(), prop.getValue().getValueAsBoolean()); } else if (edmType == EdmType.DOUBLE) { generator.writeNumberField(prop.getKey(), prop.getValue().getValueAsDouble()); } else if (edmType == EdmType.INT32) { generator.writeNumberField(prop.getKey(), prop.getValue().getValueAsInteger()); } else { generator.writeStringField(prop.getKey(), prop.getValue().getValueAsString()); } }
Example 4
Source File: FindStateIOProvider.java From constellation with Apache License 2.0 | 6 votes |
@Override public void writeObject(final Attribute attr, final int elementId, final JsonGenerator jsonGenerator, final GraphReadMethods graph, final GraphByteWriter byteWriter, final boolean verbose) throws IOException { if (verbose || !graph.isDefaultValue(attr.getId(), elementId)) { final FindState state = (FindState) graph.getObjectValue(attr.getId(), elementId); if (state == null) { jsonGenerator.writeNullField(attr.getName()); } else { jsonGenerator.writeObjectFieldStart(attr.getName()); jsonGenerator.writeStringField(GTYP, state.getGraphElementType().toString()); jsonGenerator.writeBooleanField(MODE, state.isAny()); jsonGenerator.writeBooleanField(HOLD, state.isHeld()); final Iterator<FindRule> itr = state.getRules().listIterator(); jsonGenerator.writeArrayFieldStart(RULE); while (itr.hasNext()) { addRule(jsonGenerator, itr.next()); } jsonGenerator.writeEndArray(); jsonGenerator.writeEndObject(); } } }
Example 5
Source File: HyperlinkIOProvider.java From constellation with Apache License 2.0 | 5 votes |
@Override public void writeObject(final Attribute attr, final int elementId, final JsonGenerator jsonGenerator, final GraphReadMethods graph, final GraphByteWriter byteWriter, final boolean verbose) throws IOException { if (verbose || !graph.isDefaultValue(attr.getId(), elementId)) { final String attributeValue = graph.getStringValue(attr.getId(), elementId); if (attributeValue == null) { jsonGenerator.writeNullField(attr.getName()); } else { jsonGenerator.writeStringField(attr.getName(), attributeValue); } } }
Example 6
Source File: LongObjectIOProvider.java From constellation with Apache License 2.0 | 5 votes |
@Override public void writeObject(final Attribute attribute, final int elementId, final JsonGenerator jsonGenerator, final GraphReadMethods graph, final GraphByteWriter byteWriter, final boolean verbose) throws IOException { if (verbose || !graph.isDefaultValue(attribute.getId(), elementId)) { final Long attributeValue = graph.getObjectValue(attribute.getId(), elementId); if (attributeValue != null) { jsonGenerator.writeNumberField(attribute.getName(), attributeValue); } else { jsonGenerator.writeNullField(attribute.getName()); } } }
Example 7
Source File: VertexTypeIOProvider.java From constellation with Apache License 2.0 | 5 votes |
@Override public void writeObject(final Attribute attribute, final int elementId, final JsonGenerator jsonGenerator, final GraphReadMethods graph, final GraphByteWriter byteWriter, final boolean verbose) throws IOException { if (verbose || !graph.isDefaultValue(attribute.getId(), elementId)) { final SchemaVertexType attributeValue = graph.getObjectValue(attribute.getId(), elementId); if (attributeValue == null) { jsonGenerator.writeNullField(attribute.getName()); } else { jsonGenerator.writeObjectFieldStart(attribute.getName()); writeTypeObject(attributeValue, jsonGenerator); jsonGenerator.writeEndObject(); } } }
Example 8
Source File: RawIOProvider.java From constellation with Apache License 2.0 | 5 votes |
@Override public void writeObject(final Attribute attr, final int elementId, final JsonGenerator jsonGenerator, final GraphReadMethods graph, final GraphByteWriter byteWriter, final boolean verbose) throws IOException { if (verbose || !graph.isDefaultValue(attr.getId(), elementId)) { final RawData attributeValue = graph.getObjectValue(attr.getId(), elementId); if (attributeValue == null) { jsonGenerator.writeNullField(attr.getName()); } else { jsonGenerator.writeObjectFieldStart(attr.getName()); jsonGenerator.writeStringField(RAW_IDENTIFIER_TAG, attributeValue.getRawIdentifier()); jsonGenerator.writeStringField(RAW_TYPE_TAG, attributeValue.getRawType()); jsonGenerator.writeEndObject(); } } }
Example 9
Source File: BindBean63SharedPreferences.java From kripton with Apache License 2.0 | 5 votes |
/** * for attribute valueMapStringByte serialization */ protected String serializeValueMapStringByte(Map<String, Byte> value) { if (value==null) { return null; } KriptonJsonContext context=KriptonBinder.jsonBind(); try (KriptonByteArrayOutputStream stream=new KriptonByteArrayOutputStream(); JacksonWrapperSerializer wrapper=context.createSerializer(stream)) { JsonGenerator jacksonSerializer=wrapper.jacksonGenerator; jacksonSerializer.writeStartObject(); int fieldCount=0; if (value!=null) { fieldCount++; // write wrapper tag if (value.size()>0) { jacksonSerializer.writeFieldName("valueMapStringByte"); jacksonSerializer.writeStartArray(); for (Map.Entry<String, Byte> item: value.entrySet()) { jacksonSerializer.writeStartObject(); jacksonSerializer.writeStringField("key", item.getKey()); if (item.getValue()==null) { jacksonSerializer.writeNullField("value"); } else { jacksonSerializer.writeNumberField("value", item.getValue()); } jacksonSerializer.writeEndObject(); } jacksonSerializer.writeEndArray(); } else { jacksonSerializer.writeNullField("valueMapStringByte"); } } jacksonSerializer.writeEndObject(); jacksonSerializer.flush(); return stream.toString(); } catch(Exception e) { throw(new KriptonRuntimeException(e.getMessage())); } }
Example 10
Source File: BindBeanSharedPreferences.java From kripton with Apache License 2.0 | 5 votes |
/** * for attribute valueLinkedMapStringBean serialization */ protected String serializeValueLinkedMapStringBean(LinkedHashMap<String, Bean> value) { if (value==null) { return null; } KriptonJsonContext context=KriptonBinder.jsonBind(); try (KriptonByteArrayOutputStream stream=new KriptonByteArrayOutputStream(); JacksonWrapperSerializer wrapper=context.createSerializer(stream)) { JsonGenerator jacksonSerializer=wrapper.jacksonGenerator; jacksonSerializer.writeStartObject(); int fieldCount=0; if (value!=null) { fieldCount++; // write wrapper tag if (value.size()>0) { jacksonSerializer.writeFieldName("valueLinkedMapStringBean"); jacksonSerializer.writeStartArray(); for (Map.Entry<String, Bean> item: value.entrySet()) { jacksonSerializer.writeStartObject(); jacksonSerializer.writeStringField("key", item.getKey()); if (item.getValue()==null) { jacksonSerializer.writeNullField("value"); } else { jacksonSerializer.writeFieldName("value"); beanBindMap.serializeOnJackson(item.getValue(), jacksonSerializer); } jacksonSerializer.writeEndObject(); } jacksonSerializer.writeEndArray(); } else { jacksonSerializer.writeNullField("valueLinkedMapStringBean"); } } jacksonSerializer.writeEndObject(); jacksonSerializer.flush(); return stream.toString(); } catch(Exception e) { e.printStackTrace(); throw(new KriptonRuntimeException(e.getMessage())); } }
Example 11
Source File: Bean63Table.java From kripton with Apache License 2.0 | 5 votes |
/** * for attribute valueMapEnumByte serialization */ public static byte[] serializeValueMapEnumByte(HashMap<EnumType, Byte> value) { if (value==null) { return null; } KriptonJsonContext context=KriptonBinder.jsonBind(); try (KriptonByteArrayOutputStream stream=new KriptonByteArrayOutputStream(); JacksonWrapperSerializer wrapper=context.createSerializer(stream)) { JsonGenerator jacksonSerializer=wrapper.jacksonGenerator; jacksonSerializer.writeStartObject(); int fieldCount=0; if (value!=null) { fieldCount++; // write wrapper tag if (value.size()>0) { jacksonSerializer.writeFieldName("element"); jacksonSerializer.writeStartArray(); for (Map.Entry<EnumType, Byte> item: value.entrySet()) { jacksonSerializer.writeStartObject(); jacksonSerializer.writeStringField("key", item.getKey().toString()); if (item.getValue()==null) { jacksonSerializer.writeNullField("value"); } else { jacksonSerializer.writeNumberField("value", item.getValue()); } jacksonSerializer.writeEndObject(); } jacksonSerializer.writeEndArray(); } else { jacksonSerializer.writeNullField("element"); } } jacksonSerializer.writeEndObject(); jacksonSerializer.flush(); return stream.toByteArray(); } catch(Exception e) { e.printStackTrace(); throw(new KriptonRuntimeException(e.getMessage())); } }
Example 12
Source File: LayerNameIOProvider.java From constellation with Apache License 2.0 | 5 votes |
@Override public void writeObject(final Attribute attribute, final int elementId, final JsonGenerator jsonGenerator, final GraphReadMethods graph, final GraphByteWriter byteWriter, final boolean verbose) throws IOException { if (verbose || !graph.isDefaultValue(attribute.getId(), elementId)) { final LayerName ln = (LayerName) graph.getObjectValue(attribute.getId(), elementId); if (ln != null) { jsonGenerator.writeObjectFieldStart(attribute.getName()); jsonGenerator.writeStringField(NAME_TAG, ln.getName()); jsonGenerator.writeNumberField(LAYER_TAG, ln.getLayer()); jsonGenerator.writeEndObject(); } else { jsonGenerator.writeNullField(attribute.getName()); } } }
Example 13
Source File: CustomValueWritersTest.java From jackson-jr with Apache License 2.0 | 5 votes |
@Override public void writeValue(JSONWriter context, JsonGenerator g, Object v) throws IOException { g.writeStartObject(); g.writeNumberField("answer", 42); g.writeNullField("none"); g.writeEndObject(); }
Example 14
Source File: CountryTable.java From kripton with Apache License 2.0 | 5 votes |
/** * for attribute translatedName serialization */ public static byte[] serializeTranslatedName(Map<Translation, String> value) { if (value==null) { return null; } KriptonJsonContext context=KriptonBinder.jsonBind(); try (KriptonByteArrayOutputStream stream=new KriptonByteArrayOutputStream(); JacksonWrapperSerializer wrapper=context.createSerializer(stream)) { JsonGenerator jacksonSerializer=wrapper.jacksonGenerator; jacksonSerializer.writeStartObject(); int fieldCount=0; if (value!=null) { fieldCount++; // write wrapper tag if (value.size()>0) { jacksonSerializer.writeFieldName("element"); jacksonSerializer.writeStartArray(); for (Map.Entry<Translation, String> item: value.entrySet()) { jacksonSerializer.writeStartObject(); jacksonSerializer.writeStringField("key", item.getKey().toString()); if (item.getValue()==null) { jacksonSerializer.writeNullField("value"); } else { jacksonSerializer.writeStringField("value", item.getValue()); } jacksonSerializer.writeEndObject(); } jacksonSerializer.writeEndArray(); } else { jacksonSerializer.writeNullField("element"); } } jacksonSerializer.writeEndObject(); jacksonSerializer.flush(); return stream.toByteArray(); } catch(Exception e) { e.printStackTrace(); throw(new KriptonRuntimeException(e.getMessage())); } }
Example 15
Source File: TimeZoneIOProvider.java From constellation with Apache License 2.0 | 5 votes |
@Override public void writeObject(final Attribute attr, final int elementId, final JsonGenerator jsonGenerator, final GraphReadMethods graph, final GraphByteWriter byteWriter, final boolean verbose) throws IOException { if (verbose || !graph.isDefaultValue(attr.getId(), elementId)) { final String attributeValue = graph.getStringValue(attr.getId(), elementId); if (attributeValue == null) { jsonGenerator.writeNullField(attr.getName()); } else { jsonGenerator.writeStringField(attr.getName(), attributeValue); } } }
Example 16
Source File: Bean64BTable.java From kripton with Apache License 2.0 | 5 votes |
/** * for attribute valueMapStringBean serialization */ public static byte[] serializeValueMapStringBean(Map<String, Bean64B> value) { if (value==null) { return null; } KriptonJsonContext context=KriptonBinder.jsonBind(); try (KriptonByteArrayOutputStream stream=new KriptonByteArrayOutputStream(); JacksonWrapperSerializer wrapper=context.createSerializer(stream)) { JsonGenerator jacksonSerializer=wrapper.jacksonGenerator; jacksonSerializer.writeStartObject(); int fieldCount=0; if (value!=null) { fieldCount++; // write wrapper tag if (value.size()>0) { jacksonSerializer.writeFieldName("element"); jacksonSerializer.writeStartArray(); for (Map.Entry<String, Bean64B> item: value.entrySet()) { jacksonSerializer.writeStartObject(); jacksonSerializer.writeStringField("key", item.getKey()); if (item.getValue()==null) { jacksonSerializer.writeNullField("value"); } else { jacksonSerializer.writeFieldName("value"); bean64BBindMap.serializeOnJackson(item.getValue(), jacksonSerializer); } jacksonSerializer.writeEndObject(); } jacksonSerializer.writeEndArray(); } else { jacksonSerializer.writeNullField("element"); } } jacksonSerializer.writeEndObject(); jacksonSerializer.flush(); return stream.toByteArray(); } catch(Exception e) { e.printStackTrace(); throw(new KriptonRuntimeException(e.getMessage())); } }
Example 17
Source File: CountryTable.java From kripton with Apache License 2.0 | 5 votes |
/** * for attribute translatedName serialization */ public static byte[] serializeTranslatedName(Map<Translation, String> value) { if (value==null) { return null; } KriptonJsonContext context=KriptonBinder.jsonBind(); try (KriptonByteArrayOutputStream stream=new KriptonByteArrayOutputStream(); JacksonWrapperSerializer wrapper=context.createSerializer(stream)) { JsonGenerator jacksonSerializer=wrapper.jacksonGenerator; jacksonSerializer.writeStartObject(); int fieldCount=0; if (value!=null) { fieldCount++; // write wrapper tag if (value.size()>0) { jacksonSerializer.writeFieldName("element"); jacksonSerializer.writeStartArray(); for (Map.Entry<Translation, String> item: value.entrySet()) { jacksonSerializer.writeStartObject(); jacksonSerializer.writeStringField("key", item.getKey().toString()); if (item.getValue()==null) { jacksonSerializer.writeNullField("value"); } else { jacksonSerializer.writeStringField("value", item.getValue()); } jacksonSerializer.writeEndObject(); } jacksonSerializer.writeEndArray(); } else { jacksonSerializer.writeNullField("element"); } } jacksonSerializer.writeEndObject(); jacksonSerializer.flush(); return stream.toByteArray(); } catch(Exception e) { e.printStackTrace(); throw(new KriptonRuntimeException(e.getMessage())); } }
Example 18
Source File: ResponseBindMap.java From kripton with Apache License 2.0 | 4 votes |
@Override public int serializeOnJacksonAsString(Response object, JsonGenerator jacksonSerializer) throws Exception { jacksonSerializer.writeStartObject(); int fieldCount=0; // Serialized Field: // field status (mapped with "status") if (object.status!=null) { fieldCount++; jacksonSerializer.writeStringField("status", object.status); } // field users (mapped with "users") if (object.users!=null) { fieldCount++; int n=object.users.size(); User item; // write wrapper tag jacksonSerializer.writeFieldName("users"); if (n>0) { jacksonSerializer.writeStartArray(); for (int i=0; i<n; i++) { item=object.users.get(i); if (item==null) { jacksonSerializer.writeString("null"); } else { if (userBindMap.serializeOnJacksonAsString(item, jacksonSerializer)==0) { jacksonSerializer.writeNullField("users"); } } } jacksonSerializer.writeEndArray(); } else { jacksonSerializer.writeString(""); } } // field isRealJson (mapped with "is_real_json") jacksonSerializer.writeStringField("is_real_json", PrimitiveUtils.writeBoolean(object.isRealJson)); jacksonSerializer.writeEndObject(); return fieldCount; }
Example 19
Source File: Bean81UBindMap.java From kripton with Apache License 2.0 | 4 votes |
@Override public int serializeOnJackson(Bean81U object, JsonGenerator jacksonSerializer) throws Exception { jacksonSerializer.writeStartObject(); int fieldCount=0; // Serialized Field: // field id (mapped with "id") fieldCount++; jacksonSerializer.writeNumberField("id", object.id); // field valueByteArray (mapped with "valueByteArray") if (object.valueByteArray!=null) { fieldCount++; jacksonSerializer.writeBinaryField("valueByteArray", object.valueByteArray); } // field valueInteger (mapped with "valueInteger") if (object.valueInteger!=null) { fieldCount++; jacksonSerializer.writeNumberField("valueInteger", object.valueInteger); } // field valueMapStringInteger (mapped with "valueMapStringInteger") if (object.valueMapStringInteger!=null) { fieldCount++; // write wrapper tag if (object.valueMapStringInteger.size()>0) { jacksonSerializer.writeFieldName("valueMapStringInteger"); jacksonSerializer.writeStartArray(); for (Map.Entry<String, Integer> item: object.valueMapStringInteger.entrySet()) { jacksonSerializer.writeStartObject(); jacksonSerializer.writeStringField("key", item.getKey()); if (item.getValue()==null) { jacksonSerializer.writeNullField("value"); } else { jacksonSerializer.writeNumberField("value", item.getValue()); } jacksonSerializer.writeEndObject(); } jacksonSerializer.writeEndArray(); } else { jacksonSerializer.writeNullField("valueMapStringInteger"); } } jacksonSerializer.writeEndObject(); return fieldCount; }
Example 20
Source File: Bean81SBindMap.java From kripton with Apache License 2.0 | 4 votes |
@Override public int serializeOnJackson(Bean81S object, JsonGenerator jacksonSerializer) throws Exception { jacksonSerializer.writeStartObject(); int fieldCount=0; // Serialized Field: // field id (mapped with "id") fieldCount++; jacksonSerializer.writeNumberField("id", object.id); // field valueByteArray (mapped with "valueByteArray") if (object.valueByteArray!=null) { fieldCount++; jacksonSerializer.writeBinaryField("valueByteArray", object.valueByteArray); } // field valueInteger (mapped with "valueInteger") if (object.valueInteger!=null) { fieldCount++; jacksonSerializer.writeNumberField("valueInteger", object.valueInteger); } // field valueMapStringInteger (mapped with "valueMapStringInteger") if (object.valueMapStringInteger!=null) { fieldCount++; // write wrapper tag if (object.valueMapStringInteger.size()>0) { jacksonSerializer.writeFieldName("valueMapStringInteger"); jacksonSerializer.writeStartArray(); for (Map.Entry<String, Integer> item: object.valueMapStringInteger.entrySet()) { jacksonSerializer.writeStartObject(); jacksonSerializer.writeStringField("key", item.getKey()); if (item.getValue()==null) { jacksonSerializer.writeNullField("value"); } else { jacksonSerializer.writeNumberField("value", item.getValue()); } jacksonSerializer.writeEndObject(); } jacksonSerializer.writeEndArray(); } else { jacksonSerializer.writeNullField("valueMapStringInteger"); } } jacksonSerializer.writeEndObject(); return fieldCount; }