Java Code Examples for com.fasterxml.jackson.core.JsonGenerator#writeStartArray()
The following examples show how to use
com.fasterxml.jackson.core.JsonGenerator#writeStartArray() .
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: 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 2
Source File: JacksonJson.java From gitlab4j-api with MIT License | 5 votes |
@Override public void serialize(List<User> value, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonProcessingException { jgen.writeStartArray(); for (User user : value) { jgen.writeStartObject(); jgen.writeObjectField("user", user); jgen.writeEndObject(); } jgen.writeEndArray(); }
Example 3
Source File: LngLatAltSerializer.java From geojson-jackson with Apache License 2.0 | 5 votes |
@Override public void serialize(LngLatAlt value, JsonGenerator jgen, SerializerProvider provider) throws IOException { jgen.writeStartArray(); jgen.writeNumber(value.getLongitude()); jgen.writeNumber(value.getLatitude()); if (value.hasAltitude()) { jgen.writeNumber(value.getAltitude()); for (double d : value.getAdditionalElements()) { jgen.writeNumber(d); } } jgen.writeEndArray(); }
Example 4
Source File: ExportServiceImpl.java From usergrid with Apache License 2.0 | 5 votes |
/** * Serialize and save the collection members of this <code>entity</code> * * @param em Entity Manager * @param collection Collection Name * @param entity entity */ private void saveCollectionMembers( JsonGenerator jg, EntityManager em, String collection, Entity entity ) throws Exception { // Write connections saveConnections( entity, em, jg ); // Write dictionaries saveDictionaries( entity, em, jg ); Set<String> collections = em.getCollections( entity ); // If your application doesn't have any e if ( ( collections == null ) || collections.isEmpty() ) { return; } for ( String collectionName : collections ) { if ( collectionName.equals( collection ) ) { jg.writeFieldName( collectionName ); jg.writeStartArray(); //is 100000 an arbitary number? Results collectionMembers = em.getCollection( entity, collectionName, null, 100000, Level.IDS, false ); List<UUID> entityIds = collectionMembers.getIds(); if ( ( entityIds != null ) && !entityIds.isEmpty() ) { for ( UUID childEntityUUID : entityIds ) { jg.writeObject( childEntityUUID.toString() ); } } // End collection array. jg.writeEndArray(); } } }
Example 5
Source File: JsonSignedPreKeyStore.java From signald with GNU General Public License v3.0 | 5 votes |
@Override public void serialize(JsonSignedPreKeyStore jsonPreKeyStore, JsonGenerator json, SerializerProvider serializerProvider) throws IOException, JsonProcessingException { json.writeStartArray(); for (Map.Entry<Integer, byte[]> signedPreKey : jsonPreKeyStore.store.entrySet()) { json.writeStartObject(); json.writeNumberField("id", signedPreKey.getKey()); json.writeStringField("record", Base64.encodeBytes(signedPreKey.getValue())); json.writeEndObject(); } json.writeEndArray(); }
Example 6
Source File: CharBeanTable.java From kripton with Apache License 2.0 | 5 votes |
/** * for attribute value2 serialization */ public static byte[] serializeValue2(Character[] 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++; int n=value.length; Character item; // write wrapper tag jacksonSerializer.writeFieldName("element"); jacksonSerializer.writeStartArray(); for (int i=0; i<n; i++) { item=value[i]; if (item==null) { jacksonSerializer.writeNull(); } else { jacksonSerializer.writeNumber(item); } } jacksonSerializer.writeEndArray(); } jacksonSerializer.writeEndObject(); jacksonSerializer.flush(); return stream.toByteArray(); } catch(Exception e) { e.printStackTrace(); throw(new KriptonRuntimeException(e.getMessage())); } }
Example 7
Source File: BindDataSharedPreferences.java From kripton with Apache License 2.0 | 5 votes |
/** * for attribute exampleMultiList serialization. * * @param value the value * @return the string */ protected String serializeExampleMultiList(Set<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 jacksonSerializer.writeFieldName("exampleMultiList"); jacksonSerializer.writeStartArray(); for (String item: value) { if (item==null) { jacksonSerializer.writeNull(); } else { jacksonSerializer.writeString(item); } } jacksonSerializer.writeEndArray(); } jacksonSerializer.writeEndObject(); jacksonSerializer.flush(); return stream.toString(); } catch(Exception e) { throw(new KriptonRuntimeException(e.getMessage())); } }
Example 8
Source File: Tuple1Serializer.java From cyclops with Apache License 2.0 | 5 votes |
@Override public void serialize(Tuple1<?> value, JsonGenerator gen, SerializerProvider serializers) throws IOException { Object[] array = new Object[]{value._1()}; gen.writeStartArray(); for(Object o : array) { JsonSerializer<Object> ser = serializers.findTypedValueSerializer(o.getClass(),true,null); ser.serialize(o, gen, serializers); } gen.writeEndArray(); }
Example 9
Source File: BindBean2SharedPreferences.java From kripton with Apache License 2.0 | 5 votes |
/** * for attribute valueDoubleSet serialization */ protected String serializeValueDoubleSet(HashSet<Double> 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 jacksonSerializer.writeFieldName("valueDoubleSet"); jacksonSerializer.writeStartArray(); for (Double item: value) { if (item==null) { jacksonSerializer.writeNull(); } else { jacksonSerializer.writeNumber(item); } } jacksonSerializer.writeEndArray(); } jacksonSerializer.writeEndObject(); jacksonSerializer.flush(); return stream.toString(); } catch(Exception e) { e.printStackTrace(); throw(new KriptonRuntimeException(e.getMessage())); } }
Example 10
Source File: BeanTable.java From kripton with Apache License 2.0 | 5 votes |
/** * for attribute valueCharTypeArray serialization */ public static byte[] serializeValueCharTypeArray(char[] 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++; int n=value.length; char item; // write wrapper tag jacksonSerializer.writeFieldName("element"); jacksonSerializer.writeStartArray(); for (int i=0; i<n; i++) { item=value[i]; jacksonSerializer.writeNumber(item); } jacksonSerializer.writeEndArray(); } jacksonSerializer.writeEndObject(); jacksonSerializer.flush(); return stream.toByteArray(); } catch(Exception e) { e.printStackTrace(); throw(new KriptonRuntimeException(e.getMessage())); } }
Example 11
Source File: WidgetConfigPropertiesSerializer.java From entando-core with GNU Lesser General Public License v3.0 | 5 votes |
private void writeCategories(JsonGenerator jsonGenerator, String key, String value) throws IOException { jsonGenerator.writeFieldName(key); jsonGenerator.writeStartArray(); for (String category : extractCategories(value)) { jsonGenerator.writeString(category); } jsonGenerator.writeEndArray(); }
Example 12
Source File: BeanTable.java From kripton with Apache License 2.0 | 5 votes |
/** * for attribute valueStringArray serialization */ public static byte[] serializeValueStringArray(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++; int n=value.length; String item; // write wrapper tag jacksonSerializer.writeFieldName("element"); jacksonSerializer.writeStartArray(); for (int i=0; i<n; i++) { item=value[i]; if (item==null) { jacksonSerializer.writeNull(); } else { jacksonSerializer.writeString(item); } } jacksonSerializer.writeEndArray(); } jacksonSerializer.writeEndObject(); jacksonSerializer.flush(); return stream.toByteArray(); } catch(Exception e) { e.printStackTrace(); throw(new KriptonRuntimeException(e.getMessage())); } }
Example 13
Source File: ResponseBindMap.java From kripton with Apache License 2.0 | 5 votes |
@Override public int serializeOnJackson(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"); jacksonSerializer.writeStartArray(); for (int i=0; i<n; i++) { item=object.users.get(i); if (item==null) { jacksonSerializer.writeNull(); } else { userBindMap.serializeOnJackson(item, jacksonSerializer); } } jacksonSerializer.writeEndArray(); } // field isRealJson (mapped with "is_real_json") fieldCount++; jacksonSerializer.writeBooleanField("is_real_json", object.isRealJson); jacksonSerializer.writeEndObject(); return fieldCount; }
Example 14
Source File: CharDaoImpl.java From kripton with Apache License 2.0 | 5 votes |
/** * for param serializer1 serialization */ private byte[] serializer1(char[] value) { if (value==null) { return null; } KriptonJsonContext context=KriptonBinder.jsonBind(); try (KriptonByteArrayOutputStream stream=new KriptonByteArrayOutputStream(); JacksonWrapperSerializer wrapper=context.createSerializer(stream)) { JsonGenerator jacksonSerializer=wrapper.jacksonGenerator; int fieldCount=0; jacksonSerializer.writeStartObject(); if (value!=null) { int n=value.length; char item; // write wrapper tag jacksonSerializer.writeFieldName("element"); jacksonSerializer.writeStartArray(); for (int i=0; i<n; i++) { item=value[i]; jacksonSerializer.writeNumber(item); } jacksonSerializer.writeEndArray(); } jacksonSerializer.writeEndObject(); jacksonSerializer.flush(); return stream.toByteArray(); } catch(Exception e) { e.printStackTrace(); throw(new KriptonRuntimeException(e.getMessage())); } }
Example 15
Source File: UsersStreamSerializer.java From java-json-benchmark with MIT License | 5 votes |
@Override public void jackson(JsonGenerator j, Users obj) throws IOException { j.writeStartObject(); if (obj.users != null) { j.writeFieldName("users"); j.writeStartArray(); for (User u : obj.users) { jackson(j, u); } j.writeEndArray(); } j.writeEndObject(); }
Example 16
Source File: SerializeSupport.java From curiostack with MIT License | 5 votes |
public static void printRepeatedSignedInt64(List<Long> values, JsonGenerator gen) throws IOException { int numElements = values.size(); gen.writeStartArray(numElements); for (int i = 0; i < numElements; i++) { printSignedInt64(values.get(i), gen); } gen.writeEndArray(); }
Example 17
Source File: BindBeanSharedPreferences.java From kripton with Apache License 2.0 | 5 votes |
/** * for attribute valueShortSet serialization */ protected String serializeValueShortSet(HashSet<Short> 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 jacksonSerializer.writeFieldName("valueShortSet"); jacksonSerializer.writeStartArray(); for (Short item: value) { if (item==null) { jacksonSerializer.writeNull(); } else { jacksonSerializer.writeNumber(item); } } jacksonSerializer.writeEndArray(); } jacksonSerializer.writeEndObject(); jacksonSerializer.flush(); return stream.toString(); } catch(Exception e) { e.printStackTrace(); throw(new KriptonRuntimeException(e.getMessage())); } }
Example 18
Source File: Bean03BindMap.java From kripton with Apache License 2.0 | 5 votes |
@Override public int serializeOnJackson(Bean03 object, JsonGenerator jacksonSerializer) throws Exception { jacksonSerializer.writeStartObject(); int fieldCount=0; // Serialized Field: // field miscellaneus (mapped with "miscellaneus") if (object.getMiscellaneus()!=null) { fieldCount++; int n=object.getMiscellaneus().size(); Integer item; // write wrapper tag jacksonSerializer.writeFieldName("miscellaneus"); jacksonSerializer.writeStartArray(); for (int i=0; i<n; i++) { item=object.getMiscellaneus().get(i); if (item==null) { jacksonSerializer.writeNull(); } else { jacksonSerializer.writeNumber(item); } } jacksonSerializer.writeEndArray(); } // field type (mapped with "type") if (object.getType()!=null) { fieldCount++; jacksonSerializer.writeStringField("type", object.getType()); } jacksonSerializer.writeEndObject(); return fieldCount; }
Example 19
Source File: Bean63Table.java From kripton with Apache License 2.0 | 5 votes |
/** * for attribute valueMapStringByte serialization */ public static byte[] 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("element"); 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("element"); } } jacksonSerializer.writeEndObject(); jacksonSerializer.flush(); return stream.toByteArray(); } catch(Exception e) { e.printStackTrace(); throw(new KriptonRuntimeException(e.getMessage())); } }
Example 20
Source File: Bean81TBindMap.java From kripton with Apache License 2.0 | 4 votes |
@Override public int serializeOnJacksonAsString(Bean81T object, JsonGenerator jacksonSerializer) throws Exception { jacksonSerializer.writeStartObject(); int fieldCount=0; // Serialized Field: // field id (mapped with "id") jacksonSerializer.writeStringField("id", PrimitiveUtils.writeLong(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) { jacksonSerializer.writeStringField("valueInteger", PrimitiveUtils.writeInteger(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.writeStringField("value", "null"); } else { jacksonSerializer.writeStringField("value", PrimitiveUtils.writeInteger(item.getValue())); } jacksonSerializer.writeEndObject(); } jacksonSerializer.writeEndArray(); } else { jacksonSerializer.writeStringField("valueMapStringInteger", "null"); } } jacksonSerializer.writeEndObject(); return fieldCount; }