Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 233682 Details for
Bug 411377
JSON-P - Marshal to javax.json.JsonObjectBuilder/JsonArrayBuilder
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
Additional patch
bug411377_trunk_update.patch (text/plain), 7.69 KB, created by
Denise Smith
on 2013-07-22 16:55:26 EDT
(
hide
)
Description:
Additional patch
Filename:
MIME Type:
Creator:
Denise Smith
Created:
2013-07-22 16:55:26 EDT
Size:
7.69 KB
patch
obsolete
> .../oxm/record/JsonObjectBuilderWriterRecord.java | 12 ++- > .../JsonObjectInArrayBuilderTestCases.java | 101 +++++++++++++++++++++ > .../json/rootlevellist/RootLevelListTestCases.java | 2 +- > 9 files changed, 136 insertions(+), 10 deletions(-) > >diff --git a/foundation/org.eclipse.persistence.core/src/org/eclipse/persistence/oxm/record/JsonObjectBuilderWriterRecord.java b/foundation/org.eclipse.persistence.core/src/org/eclipse/persistence/oxm/record/JsonObjectBuilderWriterRecord.java >index a7543dd..3958baf 100644 >--- a/foundation/org.eclipse.persistence.core/src/org/eclipse/persistence/oxm/record/JsonObjectBuilderWriterRecord.java >+++ b/foundation/org.eclipse.persistence.core/src/org/eclipse/persistence/oxm/record/JsonObjectBuilderWriterRecord.java >@@ -71,6 +71,7 @@ public class JsonObjectBuilderWriterRecord extends MarshalRecord <XMLMarshaller> > public JsonObjectBuilderWriterRecord(JsonArrayBuilder jsonArrayBuilder){ > this(); > rootJsonArrayBuilder = jsonArrayBuilder; >+ isRootArray = true; > } > > /** >@@ -89,6 +90,9 @@ public class JsonObjectBuilderWriterRecord extends MarshalRecord <XMLMarshaller> > @Override > public void startDocument(String encoding, String version) { > if(isRootArray){ >+ if(position == null){ >+ startCollection(); >+ } > position.setEmptyCollection(false); > > Level newLevel = new Level(false, position); >@@ -114,7 +118,10 @@ public class JsonObjectBuilderWriterRecord extends MarshalRecord <XMLMarshaller> > }else{ > //this is the root level list case > position = position.parentLevel; >- } >+ } >+ if(position !=null && isRootArray){ >+ endCollection(); >+ } > } > } > >@@ -802,7 +809,8 @@ public class JsonObjectBuilderWriterRecord extends MarshalRecord <XMLMarshaller> > if(isComplex && jsonObjectBuilder == null){ > jsonObjectBuilder = Json.createObjectBuilder(); > } >- } >+ } >+ > } > > } > >diff --git a/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/json/rootlevellist/JsonObjectInArrayBuilderTestCases.java b/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/json/rootlevellist/JsonObjectInArrayBuilderTestCases.java >new file mode 100644 >index 0000000..1dc6372 >--- /dev/null >+++ b/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/json/rootlevellist/JsonObjectInArrayBuilderTestCases.java >@@ -0,0 +1,101 @@ >+/******************************************************************************* >+ * Copyright (c) 2012 Oracle and/or its affiliates. All rights reserved. >+ * This program and the accompanying materials are made available under the >+ * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0 >+ * which accompanies this distribution. >+ * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html >+ * and the Eclipse Distribution License is available at >+ * http://www.eclipse.org/org/documents/edl-v10.php. >+ * >+ * Contributors: >+ * Denise Smith - 2.6 - initial implementation >+ ******************************************************************************/ >+package org.eclipse.persistence.testing.jaxb.json.rootlevellist; >+ >+import java.io.StringWriter; >+ >+import javax.json.Json; >+import javax.json.JsonArray; >+import javax.json.JsonArrayBuilder; >+import javax.json.JsonWriter; >+import javax.xml.bind.JAXBContext; >+import javax.xml.bind.Marshaller; >+ >+import org.eclipse.persistence.jaxb.JAXBContextFactory; >+import org.eclipse.persistence.jaxb.JAXBMarshaller; >+import org.eclipse.persistence.jaxb.MarshallerProperties; >+import org.eclipse.persistence.oxm.MediaType; >+import org.eclipse.persistence.oxm.json.JsonArrayBuilderResult; >+import org.eclipse.persistence.testing.oxm.OXTestCase; >+ >+public class JsonObjectInArrayBuilderTestCases extends OXTestCase { >+ >+ private static final String CONTROL_JSON = "org/eclipse/persistence/testing/jaxb/json/rootlevellist/WithoutXmlRootElementSingle.json"; >+ >+ public JsonObjectInArrayBuilderTestCases(String name){ >+ super(name); >+ } >+ >+ public void testMarshalToArrayBuilderResult() throws Exception{ >+ JAXBContext ctx = JAXBContextFactory.createContext(new Class[]{WithoutXmlRootElementRoot.class}, null); >+ Marshaller jsonMarshaller = ctx.createMarshaller(); >+ jsonMarshaller.setProperty(MarshallerProperties.MEDIA_TYPE, MediaType.APPLICATION_JSON); >+ jsonMarshaller.setProperty(MarshallerProperties.JSON_INCLUDE_ROOT, false); >+ >+ JsonArrayBuilder jsonArrayBuilder = Json.createArrayBuilder(); >+ JsonArrayBuilderResult result = new JsonArrayBuilderResult(jsonArrayBuilder); >+ >+ >+ WithoutXmlRootElementRoot foo = new WithoutXmlRootElementRoot(); >+ foo.setName("FOO"); >+ >+ jsonMarshaller.marshal(foo, result); >+ >+ WithoutXmlRootElementRoot foo2 = new WithoutXmlRootElementRoot(); >+ foo.setName("FOO2"); >+ >+ jsonMarshaller.marshal(foo, result); >+ >+ JsonArray jsonArray = jsonArrayBuilder.build(); >+ StringWriter sw = new StringWriter(); >+ JsonWriter writer= Json.createWriter(sw); >+ writer.writeArray(jsonArray); >+ writer.close(); >+ >+ log(sw.toString()); >+ String controlString = "[{\"name\":\"FOO\"},{\"name\":\"FOO2\"}]"; >+ assertEquals(controlString, sw.toString()); >+ } >+ >+ public void testMarshalToArrayBuilderResultWithRoot() throws Exception{ >+ JAXBContext ctx = JAXBContextFactory.createContext(new Class[]{WithXmlRootElementRoot.class}, null); >+ Marshaller jsonMarshaller = ctx.createMarshaller(); >+ jsonMarshaller.setProperty(MarshallerProperties.JSON_INCLUDE_ROOT, true); >+ jsonMarshaller.setProperty(MarshallerProperties.MEDIA_TYPE, MediaType.APPLICATION_JSON); >+ >+ JsonArrayBuilder jsonArrayBuilder = Json.createArrayBuilder(); >+ JsonArrayBuilderResult result = new JsonArrayBuilderResult(jsonArrayBuilder); >+ >+ WithXmlRootElementRoot foo = new WithXmlRootElementRoot(); >+ foo.setName("FOO"); >+ >+ jsonMarshaller.marshal(foo, result); >+ >+ WithXmlRootElementRoot foo2 = new WithXmlRootElementRoot(); >+ foo2.setName("FOO2"); >+ jsonMarshaller.marshal(foo2, result); >+ >+ JsonArray jsonArray = jsonArrayBuilder.build(); >+ StringWriter sw = new StringWriter(); >+ JsonWriter writer= Json.createWriter(sw); >+ writer.writeArray(jsonArray); >+ writer.close(); >+ >+ >+ log(sw.toString()); >+ String controlString = "[{\"root\":{\"name\":\"FOO\"}},{\"root\":{\"name\":\"FOO2\"}}]"; >+ assertEquals(controlString, sw.toString()); >+ } >+ >+ >+} >diff --git a/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/json/rootlevellist/RootLevelListTestCases.java b/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/json/rootlevellist/RootLevelListTestCases.java >index 07a05f4..3b3204e 100644 >--- a/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/json/rootlevellist/RootLevelListTestCases.java >+++ b/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/json/rootlevellist/RootLevelListTestCases.java >@@ -32,7 +32,7 @@ public class RootLevelListTestCases extends TestSuite { > > suite.addTestSuite(WithoutXmlRootElementArrayTestCases.class); > suite.addTestSuite(WithXmlRootElementArrayTestCases.class); >- >+ suite.addTestSuite(JsonObjectInArrayBuilderTestCases.class); > return suite; > } >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 411377
:
232906
|
233631
|
233635
|
233675
|
233682
|
233709
|
233732
|
233733