Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 411377

Summary: JSON-P - Marshal to javax.json.JsonObjectBuilder/JsonArrayBuilder
Product: z_Archived Reporter: Blaise Doughan <blaise.doughan>
Component: EclipselinkAssignee: Denise Smith <denise.mahar>
Status: RESOLVED FIXED QA Contact:
Severity: enhancement    
Priority: P3 CC: eclipselink.oxm-inbox
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Mac OS X   
Whiteboard:
Bug Depends on:    
Bug Blocks: 405161    
Attachments:
Description Flags
Work in progress
none
Work in progress
none
Work in progress
none
Proposed changes
none
Additional patch
none
Additional patch
none
Additional update (rename)
none
Additional update (rename) none

Description Blaise Doughan CLA 2013-06-21 10:23:25 EDT
Add support for marshalling to JsonStructure (support both JsonObject and JsonArray).  For this we should a JsonStructureResult that implements javax.xml.transform.Result.  This new result will then be able to be used with the following unmarshal methods:

Marshaller.marshal(Object, Result)

The JsonStructureResult should be able to be created with or without a root JsonStructure (much like a DOMResult).  When it is created without it should produce a new top-level JsonStructure, and when it is created with it should marshal into the existing JsonStructure.
Comment 1 Denise Smith CLA 2013-06-28 16:07:22 EDT
Created attachment 232906 [details]
Work in progress
Comment 2 Blaise Doughan CLA 2013-06-28 16:38:07 EDT
Potentially add a method like the following to JsonObjectBuilderResult

    public JsonObjectBuilder marshal(Marshaller marshaller, Object object) throws JAXBException {
        marshaller.marshal(object, this);
        return jsonObjectBuilder;
    }


This would let us fit into the JsonObjectBuilder APIs a little neater (compare how the 2nd and 4th phone numbers are added):

        JsonObjectBuilderResult result = new JsonObjectBuilderResult(cellPhoneBuilder);
        marshaller.marshal(phoneNumber, result);
        
        
        JsonObject jsonObject = Json.createObjectBuilder()
            .add("id", 123)
            .add("firstName", "Jane")
            .addNull("lastName")
            .add("phoneNumbers", Json.createArrayBuilder()
                 .add(Json.createObjectBuilder()
                      .add("type", "work")
                      .add("number", "555-1111")
                  )
                 .add(new JsonObjectBuilderResult().marshal(marshaller, phoneNumber))
                 .add(Json.createObjectBuilder()
                     .add("type", "home")
                     .add("number", "555-2222")
                  )
                  .add(result.getJsonObjectBuilder())
             )
             .build();
Comment 3 Denise Smith CLA 2013-07-19 15:43:11 EDT
Created attachment 233631 [details]
Work in progress
Comment 4 Denise Smith CLA 2013-07-19 16:16:51 EDT
Created attachment 233635 [details]
Work in progress
Comment 5 Denise Smith CLA 2013-07-22 11:02:15 EDT
Created attachment 233675 [details]
Proposed changes
Comment 6 Denise Smith CLA 2013-07-22 16:55:26 EDT
Created attachment 233682 [details]
Additional patch
Comment 7 Denise Smith CLA 2013-07-23 10:09:30 EDT
Created attachment 233709 [details]
Additional patch
Comment 8 Denise Smith CLA 2013-07-23 16:40:26 EDT
Created attachment 233732 [details]
Additional update (rename)
Comment 9 Denise Smith CLA 2013-07-23 16:51:17 EDT
Created attachment 233733 [details]
Additional update (rename)
Comment 11 Denise Smith CLA 2014-05-23 15:59:50 EDT
Changes checked in previously but bug wasn't closed.
Comment 12 Eclipse Webmaster CLA 2022-06-09 10:09:56 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink