org.codehaus.jackson.map.SerializerProvider Java Examples
The following examples show how to use
org.codehaus.jackson.map.SerializerProvider.
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: ExtensionSerDeserUtils.java From occurrence with Apache License 2.0 | 6 votes |
@Override public void serialize(List<Map<Term, String>> value, JsonGenerator jgen, SerializerProvider provider) throws IOException { if ((value == null || value.isEmpty()) && provider.getConfig().isEnabled(Feature.WRITE_EMPTY_JSON_ARRAYS)) { jgen.writeStartArray(); jgen.writeEndArray(); } else { jgen.writeStartArray(); for (Map<Term, String> extension : value) { jgen.writeStartObject(); for (Entry<Term, String> entry : extension.entrySet()) { jgen.writeStringField(entry.getKey().qualifiedName(), entry.getValue()); } jgen.writeEndObject(); } jgen.writeEndArray(); } }
Example #2
Source File: ContainerPlacementMessageObjectMapper.java From samza with Apache License 2.0 | 6 votes |
@Override public void serialize(ContainerPlacementMessage value, JsonGenerator jsonGenerator, SerializerProvider provider) throws IOException { Map<String, Object> containerPlacementMessageMap = new HashMap<String, Object>(); if (value instanceof ContainerPlacementRequestMessage) { containerPlacementMessageMap.put("subType", ContainerPlacementRequestMessage.class.getSimpleName()); } else if (value instanceof ContainerPlacementResponseMessage) { containerPlacementMessageMap.put("subType", ContainerPlacementResponseMessage.class.getSimpleName()); containerPlacementMessageMap.put("responseMessage", ((ContainerPlacementResponseMessage) value).getResponseMessage()); } if (value.getRequestExpiry() != null) { containerPlacementMessageMap.put("requestExpiry", value.getRequestExpiry().toMillis()); } containerPlacementMessageMap.put("uuid", value.getUuid().toString()); containerPlacementMessageMap.put("deploymentId", value.getDeploymentId()); containerPlacementMessageMap.put("processorId", value.getProcessorId()); containerPlacementMessageMap.put("destinationHost", value.getDestinationHost()); containerPlacementMessageMap.put("statusCode", value.getStatusCode().name()); containerPlacementMessageMap.put("timestamp", value.getTimestamp()); jsonGenerator.writeObject(containerPlacementMessageMap); }
Example #3
Source File: JsonStreamCodec.java From attic-apex-core with Apache License 2.0 | 6 votes |
public JsonStreamCodec(Map<Class<?>, Class<? extends StringCodec<?>>> codecs) { JacksonObjectMapperProvider jomp = new JacksonObjectMapperProvider(); if (codecs != null) { for (Map.Entry<Class<?>, Class<? extends StringCodec<?>>> entry: codecs.entrySet()) { try { @SuppressWarnings("unchecked") final StringCodec<Object> codec = (StringCodec<Object>)entry.getValue().newInstance(); jomp.addSerializer(new SerializerBase(entry.getKey()) { @Override public void serialize(Object value, JsonGenerator jgen, SerializerProvider provider) throws IOException { jgen.writeString(codec.toString(value)); } }); } catch (Exception ex) { logger.error("Caught exception when instantiating codec for class {}", entry.getKey().getName(), ex); } } } mapper = jomp.getContext(null); }
Example #4
Source File: JobViewSerialiser.java From jenkins-build-monitor-plugin with MIT License | 6 votes |
@Override public void serialize(JobView job, JsonGenerator jgen, SerializerProvider provider) throws IOException { jgen.writeStartObject(); jgen.writeObjectField("name", job.name()); jgen.writeObjectField("url", job.url()); jgen.writeObjectField("status", job.status()); jgen.writeObjectField("hashCode", job.hashCode()); jgen.writeObjectField("progress", job.progress()); jgen.writeObjectField("estimatedDuration", job.estimatedDuration()); for (Feature<?> feature : job.features()) { Object serialised = feature.asJson(); if (serialised != null) { jgen.writeObjectField(nameOf(serialised), serialised); } } jgen.writeEndObject(); }
Example #5
Source File: AttributesSearchQueryImpl.java From bintray-client-java with Apache License 2.0 | 6 votes |
@Override public void serialize(AttributesSearchQueryImpl value, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonProcessingException { jgen.writeStartArray(); jgen.writeStartObject(); jgen.writeArrayFieldStart(value.attributeName); @SuppressWarnings("unchecked") List<AttributesSearchQueryClauseImpl> clauses = value.getQueryClauses(); for (AttributesSearchQueryClauseImpl clause : clauses) { if (clause.getType().equals(Attribute.Type.Boolean)) { jgen.writeBoolean((Boolean) clause.getClauseValue()); } else if (clause.getType().equals(Attribute.Type.number)) { jgen.writeNumber(String.valueOf(clause.getClauseValue())); } else { //String or Date jgen.writeString((String) clause.getClauseValue()); } } jgen.writeEndArray(); jgen.writeEndObject(); jgen.writeEndArray(); }
Example #6
Source File: ObjectMapperProvider.java From hraven with Apache License 2.0 | 6 votes |
@Override public void serialize(Configuration conf, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException { SerializationContext context = RestResource.serializationContext .get(); Predicate<String> configFilter = context.getConfigurationFilter(); Iterator<Map.Entry<String, String>> keyValueIterator = conf.iterator(); jsonGenerator.writeStartObject(); // here's where we can filter out keys if we want while (keyValueIterator.hasNext()) { Map.Entry<String, String> kvp = keyValueIterator.next(); if (configFilter == null || configFilter.apply(kvp.getKey())) { jsonGenerator.writeFieldName(kvp.getKey()); jsonGenerator.writeString(kvp.getValue()); } } jsonGenerator.writeEndObject(); }
Example #7
Source File: ObjectMapperProvider.java From hraven with Apache License 2.0 | 6 votes |
@Override public void serialize(CounterMap counterMap, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException { jsonGenerator.writeStartObject(); for (String group : counterMap.getGroups()) { jsonGenerator.writeFieldName(group); jsonGenerator.writeStartObject(); Map<String, Counter> groupMap = counterMap.getGroup(group); for (String counterName : groupMap.keySet()) { Counter counter = groupMap.get(counterName); jsonGenerator.writeFieldName(counter.getKey()); jsonGenerator.writeNumber(counter.getValue()); } jsonGenerator.writeEndObject(); } jsonGenerator.writeEndObject(); }
Example #8
Source File: GenericEntitySerializer.java From secure-data-service with Apache License 2.0 | 6 votes |
@Override public void serialize(GenericEntity entity, JsonGenerator jgen, SerializerProvider provider) throws IOException { jgen.writeStartObject(); // The SLI API only supports entity body elements for PUT and POST requests. If the // entity data has a 'body' element, use that explicitly. if (entity.getData().containsKey(ENTITY_BODY_KEY)) { jgen.writeObject(serializeObject(entity.getData().get(ENTITY_BODY_KEY))); } else { for (Map.Entry<String, Object> entry : entity.getData().entrySet()) { if (entry.getKey().equals(ENTITY_LINKS_KEY) || entry.getKey().equals(ENTITY_METADATA_KEY)) { // ignore these read-only fields. continue; } jgen.writeFieldName(entry.getKey()); jgen.writeObject(serializeObject(entry.getValue())); } } jgen.writeEndObject(); }
Example #9
Source File: JsonStreamCodec.java From Bats with Apache License 2.0 | 6 votes |
public JsonStreamCodec(Map<Class<?>, Class<? extends StringCodec<?>>> codecs) { JacksonObjectMapperProvider jomp = new JacksonObjectMapperProvider(); if (codecs != null) { for (Map.Entry<Class<?>, Class<? extends StringCodec<?>>> entry : codecs.entrySet()) { try { @SuppressWarnings("unchecked") final StringCodec<Object> codec = (StringCodec<Object>) entry.getValue().newInstance(); jomp.addSerializer(new SerializerBase(entry.getKey()) { @Override public void serialize(Object value, JsonGenerator jgen, SerializerProvider provider) throws IOException { jgen.writeString(codec.toString(value)); } }); } catch (Exception ex) { logger.error("Caught exception when instantiating codec for class {}", entry.getKey().getName(), ex); } } } mapper = jomp.getContext(null); }
Example #10
Source File: CustomObjectMapper.java From jeecg with Apache License 2.0 | 6 votes |
public CustomObjectMapper() { CustomSerializerFactory factory = new CustomSerializerFactory(); factory.addGenericMapping(Date.class, new JsonSerializer<Date>() { @Override public void serialize(Date value, JsonGenerator jsonGenerator, SerializerProvider provider) throws IOException, JsonProcessingException { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String dateStr = sdf.format(value); if (dateStr.endsWith(" 00:00:00")) { dateStr = dateStr.substring(0, 10); } else if (dateStr.endsWith(":00")) { dateStr = dateStr.substring(0, 16); } jsonGenerator.writeString(dateStr); } }); this.setSerializerFactory(factory); }
Example #11
Source File: JsonDateSerializer.java From AIDR with GNU Affero General Public License v3.0 | 5 votes |
@Override public void serialize(Date date, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException { String formattedDate = null; if (date != null) { formattedDate = dateFormat.format(date); } try { jsonGenerator.writeString(formattedDate); } catch (IOException e) { logger.error("Exception while generating the json for the string:"+formattedDate, e); throw e; } }
Example #12
Source File: JsonDateSerializer.java From AIDR with GNU Affero General Public License v3.0 | 5 votes |
@Override public void serialize(Date date, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException, JsonProcessingException { String formattedDate = null; if (date != null) { formattedDate = dateFormat.format(date); } jsonGenerator.writeString(formattedDate); }
Example #13
Source File: BooleanToIntegerSerializer.java From openhab1-addons with Eclipse Public License 2.0 | 5 votes |
@Override public void serialize(Boolean bool, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException, JsonProcessingException { if (bool != null) { jsonGenerator.writeObject(bool ? 1 : 0); } }
Example #14
Source File: ObjectMapperProvider.java From hraven with Apache License 2.0 | 5 votes |
@Override public void serialize(Flow aFlow, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException { SerializationContext context = RestResource.serializationContext.get(); SerializationContext.DetailLevel selectedSerialization = context.getLevel(); Predicate<String> includeFilter = context.getFlowFilter(); writeFlowDetails(jsonGenerator, aFlow, selectedSerialization, includeFilter); }
Example #15
Source File: LinkSerializer.java From secure-data-service with Apache License 2.0 | 5 votes |
@Override public void serialize(Link link, JsonGenerator jgen, SerializerProvider provider) throws IOException { if (link == null) { jgen.writeNull(); return; } String linkString = "{\"rel\":\"" + link.getLinkName() + "\",\"href\":\"" + link.getResourceURL().toString() + "\"}"; jgen.writeRaw(linkString); }
Example #16
Source File: JsonTopologySerializer.java From libcrunch with Apache License 2.0 | 5 votes |
@Override public void serializeAsField(Object bean, JsonGenerator jgen, SerializerProvider prov) throws Exception { Object value = get(bean); if (value instanceof Boolean) { Boolean b = (Boolean)value; if (!b.booleanValue()) { // filter if "failed" is false return; } } super.serializeAsField(bean, jgen, prov); }
Example #17
Source File: CustomJsonDateSerializer.java From demo-restWS-spring-jersey-jpa2-hibernate with MIT License | 5 votes |
@Override public void serialize(Date value, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonProcessingException { SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy HH:mm"); String dateString = dateFormat.format(value); jgen.writeString(dateString); }
Example #18
Source File: JsonDateSerializer.java From ranger with Apache License 2.0 | 5 votes |
@Override public void serialize(Date date, JsonGenerator gen, SerializerProvider provider) throws IOException, JsonProcessingException { String formattedDate = new SimpleDateFormat(DATE_FORMAT).format(date); gen.writeString(formattedDate); }
Example #19
Source File: OptionalSerializer.java From incubator-myriad with Apache License 2.0 | 5 votes |
@Override public void serialize(Optional<T> value, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonProcessingException { if (value.isPresent()) { objMapper.writeValue(jgen, value.get()); } else { objMapper.writeValue(jgen, "value is absent"); } }
Example #20
Source File: TaggedLogAPIEntity.java From Eagle with Apache License 2.0 | 5 votes |
@Override public void serializeAsField(Object bean, JsonGenerator jgen, SerializerProvider provider, BeanPropertyWriter writer) throws Exception { if(bean instanceof TaggedLogAPIEntity){ TaggedLogAPIEntity entity = (TaggedLogAPIEntity) bean; Set<String> modified = entity.modifiedQualifiers(); Set<String> basePropertyNames = getPropertyNames(); String writerName = writer.getName(); if(modified.contains(writerName) || basePropertyNames.contains(writerName)){ if((!entity.isSerializeVerbose() && verboseFields.contains(writerName))|| // skip verbose fields (timestamp.equals(writerName) && !EntityDefinitionManager.isTimeSeries(entity.getClass())) // skip timestamp for non-timeseries entity ){ // log skip if(LOG.isDebugEnabled()) LOG.debug("skip field"); }else{ // if serializeAlias is not null and exp is not null if (exp.equals(writerName) && entity.getSerializeAlias()!=null && entity.getExp()!=null) { Map<String, Object> _exp = new HashMap<String, Object>(); for (Map.Entry<String, Object> entry : entity.getExp().entrySet()) { String alias = entity.getSerializeAlias().get(entry.getKey()); if (alias != null) { _exp.put(alias, entry.getValue()); } else { _exp.put(entry.getKey(), entry.getValue()); } } entity.setExp(_exp); } // write included field into serialized json output writer.serializeAsField(bean, jgen, provider); } } }else{ writer.serializeAsField(bean, jgen, provider); } }
Example #21
Source File: AppPackage.java From Bats with Apache License 2.0 | 5 votes |
@Override public void serialize( PropertyInfo propertyInfo, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonProcessingException { if (provideDescription) { jgen.writeStartObject(); jgen.writeStringField("value", propertyInfo.value); jgen.writeStringField("description", propertyInfo.description); jgen.writeEndObject(); } else { jgen.writeString(propertyInfo.value); } }
Example #22
Source File: SamzaObjectMapper.java From samza with Apache License 2.0 | 5 votes |
@Override public void serialize(SystemStreamPartition systemStreamPartition, JsonGenerator jsonGenerator, SerializerProvider provider) throws IOException, JsonProcessingException { Map<String, Object> systemStreamPartitionMap = new HashMap<String, Object>(); systemStreamPartitionMap.put("system", systemStreamPartition.getSystem()); systemStreamPartitionMap.put("stream", systemStreamPartition.getStream()); systemStreamPartitionMap.put("partition", systemStreamPartition.getPartition()); jsonGenerator.writeObject(systemStreamPartitionMap); }
Example #23
Source File: DefaultRumenSerializer.java From big-c with Apache License 2.0 | 5 votes |
public void serialize(DataType object, JsonGenerator jGen, SerializerProvider sProvider) throws IOException, JsonProcessingException { Object data = object.getValue(); if (data instanceof String) { jGen.writeString(data.toString()); } else { jGen.writeObject(data); } }
Example #24
Source File: StramWebServices.java From Bats with Apache License 2.0 | 5 votes |
@SuppressWarnings({"rawtypes", "unchecked"}) private void init() { //clear content type httpResponse.setContentType(null); if (!initialized) { Map<Class<?>, Class<? extends StringCodec<?>>> codecs = dagManager.getApplicationAttributes().get(DAGContext.STRING_CODECS); StringCodecs.loadConverters(codecs); if (codecs != null) { SimpleModule sm = new SimpleModule("DTSerializationModule", new Version(1, 0, 0, null)); for (Map.Entry<Class<?>, Class<? extends StringCodec<?>>> entry : codecs.entrySet()) { try { final StringCodec<Object> codec = (StringCodec<Object>)entry.getValue().newInstance(); sm.addSerializer(new SerializerBase(entry.getKey()) { @Override public void serialize(Object value, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonProcessingException { jgen.writeString(codec.toString(value)); } }); } catch (Exception ex) { LOG.error("Caught exception when instantiating codec for class {}", entry.getKey().getName(), ex); } } objectMapper.registerModule(sm); } initialized = true; } }
Example #25
Source File: TSSObjectMapper.java From boubei-tss with Apache License 2.0 | 5 votes |
public void serialize(Date value, JsonGenerator jsonGenerator, SerializerProvider provider) throws IOException, JsonProcessingException { String result = DateUtil.formatCare2Second(value); result = result.replaceAll(" 00:00:00", ""); jsonGenerator.writeString( result ); }
Example #26
Source File: DefaultAnonymizingRumenSerializer.java From hadoop with Apache License 2.0 | 5 votes |
public void serialize(AnonymizableDataType object, JsonGenerator jGen, SerializerProvider sProvider) throws IOException, JsonProcessingException { Object val = object.getAnonymizedValue(statePool, conf); // output the data if its a string if (val instanceof String) { jGen.writeString(val.toString()); } else { // let the mapper (JSON generator) handle this anonymized object. jGen.writeObject(val); } }
Example #27
Source File: DefaultRumenSerializer.java From hadoop with Apache License 2.0 | 5 votes |
public void serialize(DataType object, JsonGenerator jGen, SerializerProvider sProvider) throws IOException, JsonProcessingException { Object data = object.getValue(); if (data instanceof String) { jGen.writeString(data.toString()); } else { jGen.writeObject(data); } }
Example #28
Source File: MediaTypeSerializer.java From jwala with Apache License 2.0 | 5 votes |
@Override public void serialize(final MediaType mediaType, final JsonGenerator generator, final SerializerProvider provider) throws IOException { generator.writeStartObject(); generator.writeFieldName("name"); generator.writeString(mediaType.name()); generator.writeFieldName("displayName"); generator.writeString(mediaType.getDisplayName()); generator.writeEndObject(); }
Example #29
Source File: DefaultAnonymizingRumenSerializer.java From big-c with Apache License 2.0 | 5 votes |
public void serialize(AnonymizableDataType object, JsonGenerator jGen, SerializerProvider sProvider) throws IOException, JsonProcessingException { Object val = object.getAnonymizedValue(statePool, conf); // output the data if its a string if (val instanceof String) { jGen.writeString(val.toString()); } else { // let the mapper (JSON generator) handle this anonymized object. jGen.writeObject(val); } }
Example #30
Source File: StramWebServices.java From attic-apex-core with Apache License 2.0 | 5 votes |
@SuppressWarnings({"rawtypes", "unchecked"}) private void init() { //clear content type httpResponse.setContentType(null); if (!initialized) { Map<Class<?>, Class<? extends StringCodec<?>>> codecs = dagManager.getApplicationAttributes().get(DAGContext.STRING_CODECS); StringCodecs.loadConverters(codecs); if (codecs != null) { SimpleModule sm = new SimpleModule("DTSerializationModule", new Version(1, 0, 0, null)); for (Map.Entry<Class<?>, Class<? extends StringCodec<?>>> entry : codecs.entrySet()) { try { final StringCodec<Object> codec = (StringCodec<Object>)entry.getValue().newInstance(); sm.addSerializer(new SerializerBase(entry.getKey()) { @Override public void serialize(Object value, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonProcessingException { jgen.writeString(codec.toString(value)); } }); } catch (Exception ex) { LOG.error("Caught exception when instantiating codec for class {}", entry.getKey().getName(), ex); } } objectMapper.registerModule(sm); } initialized = true; } }