Java Code Examples for javax.json.bind.serializer.SerializationContext#serialize()
The following examples show how to use
javax.json.bind.serializer.SerializationContext#serialize() .
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: HalEntityWrapperJsonbSerializer.java From quarkus with Apache License 2.0 | 6 votes |
@Override public void serialize(HalEntityWrapper wrapper, JsonGenerator generator, SerializationContext context) { Marshaller marshaller = (Marshaller) context; Object entity = wrapper.getEntity(); if (!marshaller.addProcessedObject(entity)) { throw new RuntimeException("Cyclic dependency when marshaling an object"); } try { generator.writeStartObject(); ClassModel classModel = marshaller.getMappingContext().getOrCreateClassModel(entity.getClass()); for (PropertyModel property : classModel.getSortedProperties()) { if (property.isReadable()) { context.serialize(property.getWriteName(), property.getValue(entity), generator); } } writeLinks(entity, generator, context); generator.writeEnd(); } finally { marshaller.removeProcessedObject(entity); } }
Example 2
Source File: HalCollectionWrapperJsonbSerializer.java From quarkus with Apache License 2.0 | 5 votes |
private void writeEmbedded(HalCollectionWrapper wrapper, JsonGenerator generator, SerializationContext context) { generator.writeKey("_embedded"); generator.writeStartObject(); generator.writeKey(wrapper.getCollectionName()); generator.writeStartArray(); for (Object entity : wrapper.getCollection()) { context.serialize(new HalEntityWrapper(entity), generator); } generator.writeEnd(); generator.writeEnd(); }
Example 3
Source File: BookSerializer.java From Java-EE-8-Sampler with MIT License | 5 votes |
@Override public void serialize(Book book, JsonGenerator generator, SerializationContext ctx) { if (book != null) { generator.writeStartObject(); ctx.serialize(book.getClass().getName(), book, generator); generator.writeEnd(); } else { ctx.serialize(null, generator); } }
Example 4
Source File: MagazineSerializer.java From Java-EE-8-Sampler with MIT License | 5 votes |
@Override public void serialize(Magazine magazine, JsonGenerator generator, SerializationContext ctx) { if (magazine != null) { generator.writeStartObject(); ctx.serialize("name", magazine.getAuthor(), generator); generator.writeEnd(); } else { ctx.serialize(null, generator); } }
Example 5
Source File: EventJsonbSerializer.java From scalable-coffee-shop with Apache License 2.0 | 5 votes |
@Override public void serialize(final CoffeeEvent event, final JsonGenerator generator, final SerializationContext ctx) { generator.writeStartObject(); generator.write("class", event.getClass().getCanonicalName()); ctx.serialize("data", event, generator); generator.writeEnd(); generator.close(); }
Example 6
Source File: EventJsonbSerializer.java From scalable-coffee-shop with Apache License 2.0 | 5 votes |
@Override public void serialize(final CoffeeEvent event, final JsonGenerator generator, final SerializationContext ctx) { generator.writeStartObject(); generator.write("class", event.getClass().getCanonicalName()); ctx.serialize("data", event, generator); generator.writeEnd(); generator.close(); }
Example 7
Source File: EventJsonbSerializer.java From scalable-coffee-shop with Apache License 2.0 | 5 votes |
@Override public void serialize(final CoffeeEvent event, final JsonGenerator generator, final SerializationContext ctx) { generator.writeStartObject(); generator.write("class", event.getClass().getCanonicalName()); ctx.serialize("data", event, generator); generator.writeEnd(); generator.close(); }
Example 8
Source File: AddressSerializer.java From tomee with Apache License 2.0 | 5 votes |
@Override public void serialize(Address obj, JsonGenerator generator, SerializationContext ctx) { if (obj != null) { obj.setAddr("modified - " + obj.getAddr()); ctx.serialize(obj, generator); } }
Example 9
Source File: HalEntityWrapperJsonbSerializer.java From quarkus with Apache License 2.0 | 4 votes |
private void writeLinks(Object entity, JsonGenerator generator, SerializationContext context) { Map<String, HalLink> links = linksExtractor.getLinks(entity); context.serialize("_links", links, generator); }
Example 10
Source File: HalCollectionWrapperJsonbSerializer.java From quarkus with Apache License 2.0 | 4 votes |
private void writeLinks(HalCollectionWrapper wrapper, JsonGenerator generator, SerializationContext context) { Map<String, HalLink> links = linksExtractor.getLinks(wrapper.getElementType()); links.putAll(wrapper.getLinks()); context.serialize("_links", links, generator); }
Example 11
Source File: VertxJson.java From quarkus with Apache License 2.0 | 4 votes |
@Override public void serialize(JsonObject json, JsonGenerator generator, SerializationContext ctxt) { ctxt.serialize(json.getMap(), generator); }
Example 12
Source File: VertxJson.java From quarkus with Apache License 2.0 | 4 votes |
@Override public void serialize(JsonArray json, JsonGenerator generator, SerializationContext ctxt) { ctxt.serialize(json.getList(), generator); }