javax.json.bind.serializer.SerializationContext Java Examples

The following examples show how to use javax.json.bind.serializer.SerializationContext. 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 vote down vote up
@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: AddressSerializer.java    From tomee with Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(Address obj, JsonGenerator generator, SerializationContext ctx) {
	if (obj != null) {
		obj.setAddr("modified - " + obj.getAddr());
		ctx.serialize(obj, generator);
	}

}
 
Example #3
Source File: EventJsonbSerializer.java    From scalable-coffee-shop with Apache License 2.0 5 votes vote down vote up
@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 #4
Source File: EventJsonbSerializer.java    From scalable-coffee-shop with Apache License 2.0 5 votes vote down vote up
@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 #5
Source File: EventJsonbSerializer.java    From scalable-coffee-shop with Apache License 2.0 5 votes vote down vote up
@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: BookSerializer.java    From Java-EE-8-Sampler with MIT License 5 votes vote down vote up
@Override
public void serialize(Book book, JsonGenerator generator, SerializationContext ctx) {
    generator.writeStartObject();
    generator.write("id", "QWE-123-RTS");
    generator.write("title", book.getTitle());
    generator.write("firstName", book.getAuthor().split(" ")[0]);
    generator.write("lastName", book.getAuthor().split(" ")[1]);
    generator.writeEnd();
}
 
Example #7
Source File: HalCollectionWrapperJsonbSerializer.java    From quarkus with Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(HalCollectionWrapper wrapper, JsonGenerator generator, SerializationContext context) {
    generator.writeStartObject();
    writeEmbedded(wrapper, generator, context);
    writeLinks(wrapper, generator, context);
    generator.writeEnd();
}
 
Example #8
Source File: HalCollectionWrapperJsonbSerializer.java    From quarkus with Apache License 2.0 5 votes vote down vote up
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 #9
Source File: MagazineSerializer.java    From Java-EE-8-Sampler with MIT License 5 votes vote down vote up
@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 #10
Source File: BookSerializer.java    From Java-EE-8-Sampler with MIT License 5 votes vote down vote up
@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 #11
Source File: HalCollectionWrapperJsonbSerializer.java    From quarkus with Apache License 2.0 4 votes vote down vote up
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 #12
Source File: VertxJson.java    From quarkus with Apache License 2.0 4 votes vote down vote up
@Override
public void serialize(JsonArray json, JsonGenerator generator, SerializationContext ctxt) {
    ctxt.serialize(json.getList(), generator);
}
 
Example #13
Source File: VertxJson.java    From quarkus with Apache License 2.0 4 votes vote down vote up
@Override
public void serialize(JsonObject json, JsonGenerator generator, SerializationContext ctxt) {
    ctxt.serialize(json.getMap(), generator);
}
 
Example #14
Source File: Order.java    From openapi-generator with Apache License 2.0 4 votes vote down vote up
@Override
public void serialize(StatusEnum obj, JsonGenerator generator, SerializationContext ctx) {
    generator.write(obj.value);
}
 
Example #15
Source File: HalEntityWrapperJsonbSerializer.java    From quarkus with Apache License 2.0 4 votes vote down vote up
private void writeLinks(Object entity, JsonGenerator generator, SerializationContext context) {
    Map<String, HalLink> links = linksExtractor.getLinks(entity);
    context.serialize("_links", links, generator);
}
 
Example #16
Source File: HalLinkJsonbSerializer.java    From quarkus with Apache License 2.0 4 votes vote down vote up
@Override
public void serialize(HalLink value, JsonGenerator generator, SerializationContext context) {
    generator.writeStartObject();
    generator.write("href", value.getHref());
    generator.writeEnd();
}
 
Example #17
Source File: ObjectIdSerializer.java    From quarkus with Apache License 2.0 4 votes vote down vote up
@Override
public void serialize(ObjectId obj, JsonGenerator generator, SerializationContext ctx) {
    if (obj != null) {
        generator.write(obj.toString());
    }
}
 
Example #18
Source File: ModelWithSerializerAndDeserializerOnField.java    From quarkus with Apache License 2.0 4 votes vote down vote up
@Override
public void serialize(Inner obj, JsonGenerator gen, SerializationContext ctx) {
    gen.writeStartObject();
    gen.write("someValue", "unchangeable");
    gen.writeEnd();
}
 
Example #19
Source File: Pet.java    From openapi-generator with Apache License 2.0 4 votes vote down vote up
@Override
public void serialize(StatusEnum obj, JsonGenerator generator, SerializationContext ctx) {
    generator.write(obj.value);
}