SHOW:
|
|
- or go back to the newest paste.
1 | Index: MOXyJsonProvider.java | |
2 | =================================================================== | |
3 | --- MOXyJsonProvider.java (revision 557) | |
4 | +++ MOXyJsonProvider.java (revision 556) | |
5 | @@ -68,8 +68,8 @@ | |
6 | import org.eclipse.persistence.internal.queries.CollectionContainerPolicy; | |
7 | import org.eclipse.persistence.internal.queries.ContainerPolicy; | |
8 | import org.eclipse.persistence.jaxb.JAXBContextFactory; | |
9 | -import org.eclipse.persistence.jaxb.JAXBContextProperties; | |
10 | import org.eclipse.persistence.jaxb.MarshallerProperties; | |
11 | +import org.eclipse.persistence.jaxb.UnmarshallerProperties; | |
12 | import org.eclipse.persistence.oxm.JSONWithPadding; | |
13 | ||
14 | /** | |
15 | @@ -217,12 +217,12 @@ | |
16 | private char namespaceSeperator = Constants.DOT; | |
17 | private String valueWrapper; | |
18 | private boolean wrapperAsArrayName = false; | |
19 | - private Object oxmMetadataSource = null; | |
20 | ||
21 | /** | |
22 | * The value that will be prepended to all keys that are mapped to an XML | |
23 | * attribute. By default there is no attribute prefix. | |
24 | - * @see org.eclipse.persistence.jaxb.JAXBContextProperties.JSON_ATTRIBUTE_PREFIX | |
25 | + * @see org.eclipse.persistence.jaxb.MarshallerPropertes.JSON_ATTRIBUTE_PREFIX | |
26 | + * @see org.eclipse.persistence.jaxb.UnmarshallerPropertes.JSON_ATTRIBUTE_PREFIX | |
27 | */ | |
28 | public String getAttributePrefix() { | |
29 | return attributePrefix; | |
30 | @@ -300,43 +300,18 @@ | |
31 | resolver = providers.getContextResolver(JAXBContext.class, mediaType); | |
32 | } | |
33 | if(null == resolver || null == (jaxbContext = resolver.getContext(domainClass))) { | |
34 | - jaxbContext = JAXBContextFactory.createContext(new Class[] {domainClass}, | |
35 | - prepareContextProperties()); | |
36 | + jaxbContext = JAXBContextFactory.createContext(new Class[] {domainClass}, null); | |
37 | contextCache.put(domainClass, jaxbContext); | |
38 | return jaxbContext; | |
39 | } else if (jaxbContext instanceof org.eclipse.persistence.jaxb.JAXBContext) { | |
40 | return jaxbContext; | |
41 | } else { | |
42 | - jaxbContext = JAXBContextFactory.createContext(new Class[] {domainClass}, | |
43 | - prepareContextProperties()); | |
44 | + jaxbContext = JAXBContextFactory.createContext(new Class[] {domainClass}, null); | |
45 | contextCache.put(domainClass, jaxbContext); | |
46 | return jaxbContext; | |
47 | } | |
48 | } | |
49 | ||
50 | - private Map<String, Object> prepareContextProperties() { | |
51 | - Map<String, Object> contextProperties = new HashMap<>(); | |
52 | - | |
53 | - contextProperties.put(JAXBContextProperties.MEDIA_TYPE, MediaType.APPLICATION_JSON); | |
54 | - contextProperties.put(JAXBContextProperties.JSON_ATTRIBUTE_PREFIX, attributePrefix); | |
55 | - contextProperties.put(JAXBContextProperties.JSON_INCLUDE_ROOT, includeRoot); | |
56 | - contextProperties.put(JAXBContextProperties.NAMESPACE_PREFIX_MAPPER, namespacePrefixMapper); | |
57 | - contextProperties.put(JAXBContextProperties.JSON_NAMESPACE_SEPARATOR, namespaceSeperator); | |
58 | - if(null != valueWrapper) { | |
59 | - contextProperties.put(JAXBContextProperties.JSON_VALUE_WRAPPER, valueWrapper); | |
60 | - } | |
61 | - contextProperties.put(JAXBContextProperties.JSON_WRAPPER_AS_ARRAY_NAME, wrapperAsArrayName); | |
62 | - contextProperties.put(JAXBContextProperties.OXM_METADATA_SOURCE, oxmMetadataSource); | |
63 | - | |
64 | - overrideContextProperties(contextProperties); | |
65 | - | |
66 | - return contextProperties; | |
67 | - } | |
68 | - | |
69 | - protected void overrideContextProperties(Map<String, Object> contextProperties) { | |
70 | - | |
71 | - } | |
72 | - | |
73 | private JAXBContext getJAXBContext(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) { | |
74 | if(null == genericType) { | |
75 | genericType = type; | |
76 | @@ -354,7 +329,8 @@ | |
77 | * By default the JSON-binding will ignore namespace qualification. If this | |
78 | * property is set the portion of the key before the namespace separator | |
79 | * will be used to determine the namespace URI. | |
80 | - * @see org.eclipse.persistence.jaxb.JAXBContextProperties.NAMESPACE_PREFIX_MAPPER | |
81 | + * @see org.eclipse.persistence.jaxb.MarshallerProperties.NAMESPACE_PREFIX_MAPPER | |
82 | + * @see org.eclipse.persistence.jaxb.UnmarshallerProperties.JSON_NAMESPACE_PREFIX_MAPPER | |
83 | */ | |
84 | public Map<String, String> getNamespacePrefixMapper() { | |
85 | return namespacePrefixMapper; | |
86 | @@ -364,16 +340,13 @@ | |
87 | * This character (default is '.') separates the prefix from the key name. | |
88 | * It is only used if namespace qualification has been enabled be setting a | |
89 | * namespace prefix mapper. | |
90 | - * @see org.eclipse.persistence.jaxb.JAXBContextProperties.JSON_NAMESPACE_SEPARATOR | |
91 | + * @see org.eclipse.persistence.jaxb.MarshallerProperties.NAMESPACE_SEPARATOR | |
92 | + * @see org.eclipse.persistence.jaxb.UnmarshallerProperties.NAMESPACE_SEPARATOR | |
93 | */ | |
94 | public char getNamespaceSeparator() { | |
95 | return this.namespaceSeperator; | |
96 | } | |
97 | ||
98 | - public Object getOxmMetadataSource() { | |
99 | - return this.oxmMetadataSource; | |
100 | - } | |
101 | - | |
102 | /* | |
103 | * @return -1 since the size of the JSON message is not known. | |
104 | * @see javax.ws.rs.ext.MessageBodyWriter#getSize(java.lang.Object, java.lang.Class, java.lang.reflect.Type, java.lang.annotation.Annotation[], javax.ws.rs.core.MediaType) | |
105 | @@ -385,7 +358,8 @@ | |
106 | /** | |
107 | * The key that will correspond to the property mapped with @XmlValue. This | |
108 | * key will only be used if there are other mapped properties. | |
109 | - * @see org.eclipse.persistence.jaxb.JAXBContextProperties.JSON_VALUE_WRAPPER | |
110 | + * @see org.eclipse.persistence.jaxb.MarshallerPropertes.JSON_VALUE_WRAPPER | |
111 | + * @see org.eclipse.persistence.jaxb.UnmarshallerPropertes.JSON_VALUE_WRAPPER | |
112 | */ | |
113 | public String getValueWrapper() { | |
114 | return valueWrapper; | |
115 | @@ -401,7 +375,8 @@ | |
116 | /** | |
117 | * @return true if the root node is included in the JSON message (default is | |
118 | * false). | |
119 | - * @see org.eclipse.persistence.jaxb.JAXBContextProperties.JSON_INCLUDE_ROOT | |
120 | + * @see org.eclipse.persistence.jaxb.MarshallerPropertes.JSON_INCLUDE_ROOT | |
121 | + * @see org.eclipse.persistence.jaxb.UnmarshallerPropertes.JSON_INCLUDE_ROOT | |
122 | */ | |
123 | public boolean isIncludeRoot() { | |
124 | return includeRoot; | |
125 | @@ -502,6 +477,8 @@ | |
126 | * </pre> | |
127 | * @since 2.4.2 | |
128 | * @see org.eclipse.persistence.jaxb.JAXBContextProperties.JSON_WRAPPER_AS_ARRAY_NAME | |
129 | + * @see org.eclipse.persistence.jaxb.MarshallerProperties.JSON_WRAPPER_AS_ARRAY_NAME | |
130 | + * @see org.eclipse.persistence.jaxb.UnmarshallerProperties.JSON_WRAPPER_AS_ARRAY_NAME | |
131 | */ | |
132 | public boolean isWrapperAsArrayName() { | |
133 | return wrapperAsArrayName; | |
134 | @@ -609,6 +586,15 @@ | |
135 | Class<?> domainClass = getDomainClass(genericType); | |
136 | JAXBContext jaxbContext = getJAXBContext(domainClass, annotations, mediaType, httpHeaders); | |
137 | Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); | |
138 | + unmarshaller.setProperty(UnmarshallerProperties.MEDIA_TYPE, MediaType.APPLICATION_JSON); | |
139 | + unmarshaller.setProperty(UnmarshallerProperties.JSON_ATTRIBUTE_PREFIX, attributePrefix); | |
140 | + unmarshaller.setProperty(UnmarshallerProperties.JSON_INCLUDE_ROOT, includeRoot); | |
141 | + unmarshaller.setProperty(UnmarshallerProperties.JSON_NAMESPACE_PREFIX_MAPPER, namespacePrefixMapper); | |
142 | + unmarshaller.setProperty(UnmarshallerProperties.JSON_NAMESPACE_SEPARATOR, namespaceSeperator); | |
143 | + if(null != valueWrapper) { | |
144 | + unmarshaller.setProperty(UnmarshallerProperties.JSON_VALUE_WRAPPER, valueWrapper); | |
145 | + } | |
146 | + unmarshaller.setProperty(UnmarshallerProperties.JSON_WRAPPER_AS_ARRAY_NAME, wrapperAsArrayName); | |
147 | preReadFrom(type, genericType, annotations, mediaType, httpHeaders, unmarshaller); | |
148 | ||
149 | StreamSource jsonSource; | |
150 | @@ -707,7 +693,8 @@ | |
151 | /** | |
152 | * Specify a value that will be prepended to all keys that are mapped to an | |
153 | * XML attribute. By default there is no attribute prefix. | |
154 | - * @see org.eclipse.persistence.jaxb.JAXBContextProperties.JSON_ATTRIBUTE_PREFIX | |
155 | + * @see org.eclipse.persistence.jaxb.MarshallerPropertes.JSON_ATTRIBUTE_PREFIX | |
156 | + * @see org.eclipse.persistence.jaxb.UnmarshallerPropertes.JSON_ATTRIBUTE_PREFIX | |
157 | */ | |
158 | public void setAttributePrefix(String attributePrefix) { | |
159 | this.attributePrefix = attributePrefix; | |
160 | @@ -727,7 +714,8 @@ | |
161 | * is false). | |
162 | * @param includeRoot - true if the message includes the root node, else | |
163 | * false. | |
164 | - * @see org.eclipse.persistence.jaxb.JAXBContextProperties.JSON_INCLUDE_ROOT | |
165 | + * @see org.eclipse.persistence.jaxb.MarshallerPropertes.JSON_INCLUDE_ROOT | |
166 | + * @see org.eclipse.persistence.jaxb.UnmarshallerPropertes.JSON_INCLUDE_ROOT | |
167 | */ | |
168 | public void setIncludeRoot(boolean includeRoot) { | |
169 | this.includeRoot = includeRoot; | |
170 | @@ -747,7 +735,8 @@ | |
171 | * property is set then a prefix corresponding to the namespace URI and a | |
172 | * namespace separator will be prefixed to the key. | |
173 | * include it you can specify a Map of namespace URI to prefix. | |
174 | - * @see org.eclipse.persistence.jaxb.JAXBContextProperties.NAMESPACE_PREFIX_MAPPER | |
175 | + * @see org.eclipse.persistence.jaxb.MarshallerProperties.NAMESPACE_PREFIX_MAPPER | |
176 | + * @see org.eclipse.persistence.jaxb.UnmarshallerProperties.JSON_NAMESPACE_PREFIX_MAPPER | |
177 | */ | |
178 | public void setNamespacePrefixMapper(Map<String, String> namespacePrefixMapper) { | |
179 | this.namespacePrefixMapper = namespacePrefixMapper; | |
180 | @@ -757,7 +746,8 @@ | |
181 | * This character (default is '.') separates the prefix from the key name. | |
182 | * It is only used if namespace qualification has been enabled be setting a | |
183 | * namespace prefix mapper. | |
184 | - * @see org.eclipse.persistence.jaxb.JAXBContextProperties.JSON_NAMESPACE_SEPARATOR | |
185 | + * @see org.eclipse.persistence.jaxb.MarshallerProperties.NAMESPACE_SEPARATOR | |
186 | + * @see org.eclipse.persistence.jaxb.UnmarshallerProperties.NAMESPACE_SEPARATOR | |
187 | */ | |
188 | public void setNamespaceSeparator(char namespaceSeparator) { | |
189 | this.namespaceSeperator = namespaceSeparator; | |
190 | @@ -802,6 +792,8 @@ | |
191 | * </pre> | |
192 | * @since 2.4.2 | |
193 | * @see org.eclipse.persistence.jaxb.JAXBContextProperties.JSON_WRAPPER_AS_ARRAY_NAME | |
194 | + * @see org.eclipse.persistence.jaxb.MarshallerProperties.JSON_WRAPPER_AS_ARRAY_NAME | |
195 | + * @see org.eclipse.persistence.jaxb.UnmarshallerProperties.JSON_WRAPPER_AS_ARRAY_NAME | |
196 | */ | |
197 | public void setWrapperAsArrayName(boolean wrapperAsArrayName) { | |
198 | this.wrapperAsArrayName = wrapperAsArrayName; | |
199 | @@ -811,16 +803,13 @@ | |
200 | * Specify the key that will correspond to the property mapped with | |
201 | * @XmlValue. This key will only be used if there are other mapped | |
202 | * properties. | |
203 | - * @see org.eclipse.persistence.jaxb.JAXBContextProperties.JSON_VALUE_WRAPPER | |
204 | + * @see org.eclipse.persistence.jaxb.MarshallerPropertes.JSON_VALUE_WRAPPER | |
205 | + * @see org.eclipse.persistence.jaxb.UnmarshallerPropertes.JSON_VALUE_WRAPPER | |
206 | */ | |
207 | public void setValueWrapper(String valueWrapper) { | |
208 | this.valueWrapper = valueWrapper; | |
209 | } | |
210 | ||
211 | - public void setOxmMetadataSource(Object oxmMetadataSource) { | |
212 | - this.oxmMetadataSource = oxmMetadataSource; | |
213 | - } | |
214 | - | |
215 | /** | |
216 | * @return true for all media types of the pattern */json and | |
217 | * */*+json. | |
218 | @@ -846,7 +835,16 @@ | |
219 | JAXBContext jaxbContext = getJAXBContext(domainClass, annotations, mediaType, httpHeaders); | |
220 | Marshaller marshaller = jaxbContext.createMarshaller(); | |
221 | marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, formattedOutput); | |
222 | + marshaller.setProperty(MarshallerProperties.MEDIA_TYPE, MediaType.APPLICATION_JSON); | |
223 | + marshaller.setProperty(MarshallerProperties.JSON_ATTRIBUTE_PREFIX, attributePrefix); | |
224 | + marshaller.setProperty(MarshallerProperties.JSON_INCLUDE_ROOT, includeRoot); | |
225 | marshaller.setProperty(MarshallerProperties.JSON_MARSHAL_EMPTY_COLLECTIONS, marshalEmptyCollections); | |
226 | + marshaller.setProperty(MarshallerProperties.JSON_NAMESPACE_SEPARATOR, namespaceSeperator); | |
227 | + if(null != valueWrapper) { | |
228 | + marshaller.setProperty(MarshallerProperties.JSON_VALUE_WRAPPER, valueWrapper); | |
229 | + } | |
230 | + marshaller.setProperty(MarshallerProperties.JSON_WRAPPER_AS_ARRAY_NAME, wrapperAsArrayName); | |
231 | + marshaller.setProperty(MarshallerProperties.NAMESPACE_PREFIX_MAPPER, namespacePrefixMapper); | |
232 | ||
233 | Map<String, String> mediaTypeParameters = null; | |
234 | if(null != mediaType) { | |
235 | ||
236 | Index: MoxyJsonConfig.java | |
237 | =================================================================== | |
238 | --- MoxyJsonConfig.java (revision 557) | |
239 | +++ MoxyJsonConfig.java (revision 556) | |
240 | @@ -46,8 +46,8 @@ | |
241 | ||
242 | import javax.xml.bind.Marshaller; | |
243 | ||
244 | -import org.eclipse.persistence.jaxb.JAXBContextProperties; | |
245 | import org.eclipse.persistence.jaxb.MarshallerProperties; | |
246 | +import org.eclipse.persistence.jaxb.UnmarshallerProperties; | |
247 | import org.eclipse.persistence.oxm.XMLConstants; | |
248 | ||
249 | /** | |
250 | @@ -57,7 +57,6 @@ | |
251 | */ | |
252 | public final class MoxyJsonConfig { | |
253 | ||
254 | - private final Map<String, Object> contextProperties = new HashMap<>(); | |
255 | private final Map<String, Object> marshallerProperties = new HashMap<>(); | |
256 | private final Map<String, Object> unmarshallerProperties = new HashMap<>(); | |
257 | ||
258 | @@ -105,20 +104,20 @@ | |
259 | * @param that config to make a copy of. | |
260 | */ | |
261 | private MoxyJsonConfig(final MoxyJsonConfig that) { | |
262 | - this.contextProperties.putAll(that.contextProperties); | |
263 | this.marshallerProperties.putAll(that.marshallerProperties); | |
264 | this.unmarshallerProperties.putAll(that.unmarshallerProperties); | |
265 | } | |
266 | ||
267 | /** | |
268 | - * Set the value of the property for used {@code JAXBContext}. | |
269 | + * Set the value of the property for both {@code Marshaller} / {@code Unmarshaller}. | |
270 | * | |
271 | * @param name name of the property. | |
272 | * @param value value of the property. | |
273 | * @return a {@code MoxyJsonConfig} instance. | |
274 | */ | |
275 | - public MoxyJsonConfig contextProperty(final String name, final Object value) { | |
276 | - contextProperties.put(name, value); | |
277 | + public MoxyJsonConfig property(final String name, final Object value) { | |
278 | + marshallerProperty(name, value); | |
279 | + unmarshallerProperty(name, value); | |
280 | return this; | |
281 | } | |
282 | ||
283 | @@ -147,17 +146,6 @@ | |
284 | } | |
285 | ||
286 | /** | |
287 | - * Add properties from the given map to the existing context properties. | |
288 | - * | |
289 | - * @param contextProperties map of marshaller properties. | |
290 | - * @return a {@code MoxyJsonConfig} instance. | |
291 | - */ | |
292 | - public MoxyJsonConfig setContextProperties(final Map<String, Object> contextProperties) { | |
293 | - this.contextProperties.putAll(contextProperties); | |
294 | - return this; | |
295 | - } | |
296 | - | |
297 | - /** | |
298 | * Add properties from the given map to the existing marshaller properties. | |
299 | * | |
300 | * @param marshallerProperties map of marshaller properties. | |
301 | @@ -180,15 +168,6 @@ | |
302 | } | |
303 | ||
304 | /** | |
305 | - * Get context properties. | |
306 | - * | |
307 | - * @return mutable map of context properties. | |
308 | - */ | |
309 | - public Map<String, Object> getContextProperties() { | |
310 | - return contextProperties; | |
311 | - } | |
312 | - | |
313 | - /** | |
314 | * Get marshaller properties. | |
315 | * | |
316 | * @return mutable map of marshaller properties. | |
317 | @@ -210,7 +189,7 @@ | |
318 | * @see org.eclipse.persistence.jaxb.rs.MOXyJsonProvider#getAttributePrefix() | |
319 | */ | |
320 | public String getAttributePrefix() { | |
321 | - return (String) contextProperties.get(JAXBContextProperties.JSON_ATTRIBUTE_PREFIX); | |
322 | + return (String) marshallerProperties.get(MarshallerProperties.JSON_ATTRIBUTE_PREFIX); | |
323 | } | |
324 | ||
325 | /** | |
326 | @@ -218,9 +197,11 @@ | |
327 | */ | |
328 | public MoxyJsonConfig setAttributePrefix(final String attributePrefix) { | |
329 | if (attributePrefix != null) { | |
330 | - contextProperties.put(JAXBContextProperties.JSON_ATTRIBUTE_PREFIX, attributePrefix); | |
331 | + marshallerProperties.put(MarshallerProperties.JSON_ATTRIBUTE_PREFIX, attributePrefix); | |
332 | + unmarshallerProperties.put(UnmarshallerProperties.JSON_ATTRIBUTE_PREFIX, attributePrefix); | |
333 | } else { | |
334 | - contextProperties.remove(MarshallerProperties.JSON_ATTRIBUTE_PREFIX); | |
335 | + marshallerProperties.remove(MarshallerProperties.JSON_ATTRIBUTE_PREFIX); | |
336 | + unmarshallerProperties.remove(UnmarshallerProperties.JSON_ATTRIBUTE_PREFIX); | |
337 | } | |
338 | return this; | |
339 | } | |
340 | @@ -244,7 +225,7 @@ | |
341 | * @see org.eclipse.persistence.jaxb.rs.MOXyJsonProvider#isIncludeRoot() | |
342 | */ | |
343 | public boolean isIncludeRoot() { | |
344 | - return (Boolean) contextProperties.get(JAXBContextProperties.JSON_INCLUDE_ROOT); | |
345 | + return (Boolean) marshallerProperties.get(MarshallerProperties.JSON_INCLUDE_ROOT); | |
346 | } | |
347 | ||
348 | /** | |
349 | @@ -251,7 +232,8 @@ | |
350 | * @see org.eclipse.persistence.jaxb.rs.MOXyJsonProvider#setIncludeRoot(boolean) | |
351 | */ | |
352 | public MoxyJsonConfig setIncludeRoot(final boolean includeRoot) { | |
353 | - contextProperties.put(JAXBContextProperties.JSON_INCLUDE_ROOT, includeRoot); | |
354 | + marshallerProperties.put(MarshallerProperties.JSON_INCLUDE_ROOT, includeRoot); | |
355 | + unmarshallerProperties.put(UnmarshallerProperties.JSON_INCLUDE_ROOT, includeRoot); | |
356 | return this; | |
357 | } | |
358 | ||
359 | @@ -274,7 +256,7 @@ | |
360 | * @see org.eclipse.persistence.jaxb.rs.MOXyJsonProvider#getNamespacePrefixMapper() | |
361 | */ | |
362 | public Map<String, String> getNamespacePrefixMapper() { | |
363 | - return (Map<String, String>) contextProperties.get(JAXBContextProperties.NAMESPACE_PREFIX_MAPPER); | |
364 | + return (Map<String, String>) marshallerProperties.get(MarshallerProperties.NAMESPACE_PREFIX_MAPPER); | |
365 | } | |
366 | ||
367 | /** | |
368 | @@ -282,9 +264,11 @@ | |
369 | */ | |
370 | public MoxyJsonConfig setNamespacePrefixMapper(final Map<String, String> namespacePrefixMapper) { | |
371 | if (namespacePrefixMapper != null) { | |
372 | - contextProperties.put(JAXBContextProperties.NAMESPACE_PREFIX_MAPPER, namespacePrefixMapper); | |
373 | + marshallerProperties.put(MarshallerProperties.NAMESPACE_PREFIX_MAPPER, namespacePrefixMapper); | |
374 | + unmarshallerProperties.put(UnmarshallerProperties.JSON_NAMESPACE_PREFIX_MAPPER, namespacePrefixMapper); | |
375 | } else { | |
376 | - contextProperties.remove(JAXBContextProperties.NAMESPACE_PREFIX_MAPPER); | |
377 | + marshallerProperties.remove(MarshallerProperties.NAMESPACE_PREFIX_MAPPER); | |
378 | + unmarshallerProperties.remove(UnmarshallerProperties.JSON_NAMESPACE_PREFIX_MAPPER); | |
379 | } | |
380 | return this; | |
381 | } | |
382 | @@ -293,7 +277,7 @@ | |
383 | * @see org.eclipse.persistence.jaxb.rs.MOXyJsonProvider#getNamespaceSeparator() | |
384 | */ | |
385 | public char getNamespaceSeparator() { | |
386 | - return (Character) contextProperties.get(JAXBContextProperties.JSON_NAMESPACE_SEPARATOR); | |
387 | + return (Character) marshallerProperties.get(MarshallerProperties.JSON_NAMESPACE_SEPARATOR); | |
388 | } | |
389 | ||
390 | /** | |
391 | @@ -300,7 +284,8 @@ | |
392 | * @see org.eclipse.persistence.jaxb.rs.MOXyJsonProvider#setNamespaceSeparator(char) | |
393 | */ | |
394 | public MoxyJsonConfig setNamespaceSeparator(final char namespaceSeparator) { | |
395 | - contextProperties.put(JAXBContextProperties.JSON_NAMESPACE_SEPARATOR, namespaceSeparator); | |
396 | + marshallerProperties.put(MarshallerProperties.JSON_NAMESPACE_SEPARATOR, namespaceSeparator); | |
397 | + unmarshallerProperties.put(UnmarshallerProperties.JSON_NAMESPACE_SEPARATOR, namespaceSeparator); | |
398 | return this; | |
399 | } | |
400 | ||
401 | @@ -308,7 +293,7 @@ | |
402 | * @see org.eclipse.persistence.jaxb.rs.MOXyJsonProvider#getValueWrapper() | |
403 | */ | |
404 | public String getValueWrapper() { | |
405 | - return (String) contextProperties.get(JAXBContextProperties.JSON_VALUE_WRAPPER); | |
406 | + return (String) marshallerProperties.get(MarshallerProperties.JSON_VALUE_WRAPPER); | |
407 | } | |
408 | ||
409 | /** | |
410 | @@ -316,33 +301,16 @@ | |
411 | */ | |
412 | public MoxyJsonConfig setValueWrapper(final String valueWrapper) { | |
413 | if (valueWrapper != null) { | |
414 | - contextProperties.put(JAXBContextProperties.JSON_VALUE_WRAPPER, valueWrapper); | |
415 | + marshallerProperties.put(MarshallerProperties.JSON_VALUE_WRAPPER, valueWrapper); | |
416 | + unmarshallerProperties.put(UnmarshallerProperties.JSON_VALUE_WRAPPER, valueWrapper); | |
417 | } else { | |
418 | - contextProperties.remove(JAXBContextProperties.JSON_VALUE_WRAPPER); | |
419 | + marshallerProperties.remove(MarshallerProperties.JSON_VALUE_WRAPPER); | |
420 | + unmarshallerProperties.remove(UnmarshallerProperties.JSON_VALUE_WRAPPER); | |
421 | } | |
422 | return this; | |
423 | } | |
424 | ||
425 | /** | |
426 | - * | |
427 | - */ | |
428 | - public Object getOxmMedatadataSource() { | |
429 | - return contextProperties.get(JAXBContextProperties.OXM_METADATA_SOURCE); | |
430 | - } | |
431 | - | |
432 | - /** | |
433 | - * | |
434 | - */ | |
435 | - public MoxyJsonConfig setOxmMedatadataSource(final Object oxmMedatadataSource) { | |
436 | - if (oxmMedatadataSource != null) { | |
437 | - contextProperties.put(JAXBContextProperties.OXM_METADATA_SOURCE, oxmMedatadataSource); | |
438 | - } else { | |
439 | - contextProperties.remove(JAXBContextProperties.OXM_METADATA_SOURCE); | |
440 | - } | |
441 | - return this; | |
442 | - } | |
443 | - | |
444 | - /** | |
445 | * Create a {@link ContextResolver context resolver} for a current state of this {@code MoxyJsonConfig}. | |
446 | * | |
447 | * @return context resolver for this config. | |
448 | ||
449 | Index: ConfigurableMoxyJsonProvider.java | |
450 | =================================================================== | |
451 | --- ConfigurableMoxyJsonProvider.java (revision 557) | |
452 | +++ ConfigurableMoxyJsonProvider.java (revision 556) | |
453 | @@ -68,7 +68,6 @@ | |
454 | - | import com.siemens.dynamowerk.x2tcproxy.jersey.moxy.json.MoxyJsonConfig; |
454 | + | import ...jersey.moxy.json.MoxyJsonConfig; |
455 | ||
456 | import org.eclipse.persistence.internal.core.helper.CoreClassConstants; | |
457 | -import org.eclipse.persistence.jaxb.JAXBContextProperties; | |
458 | import org.eclipse.persistence.jaxb.MarshallerProperties; | |
459 | import org.eclipse.persistence.jaxb.UnmarshallerProperties; | |
460 | ||
461 | @@ -80,17 +79,11 @@ | |
462 | @Singleton | |
463 | public class ConfigurableMoxyJsonProvider extends MOXyJsonProvider { | |
464 | ||
465 | - private final static Set<String> CONTEXT_PROPERTY_NAMES; | |
466 | - private final static Set<String> MARSHALLER_PROPERTY_NAMES; | |
467 | + private final static Set<String> MARSHALLER_PROPERTY_NAMES; | |
468 | private final static Set<String> UNMARSHALLER_PROPERTY_NAMES; | |
469 | ||
470 | - private enum PropertiesType { | |
471 | - MARSHALLER, UNMARSHALLER, CONTEXT; | |
472 | - } | |
473 | - | |
474 | static { | |
475 | - CONTEXT_PROPERTY_NAMES = getPropertyNames(JAXBContextProperties.class); | |
476 | - MARSHALLER_PROPERTY_NAMES = getPropertyNames(MarshallerProperties.class); | |
477 | + MARSHALLER_PROPERTY_NAMES = getPropertyNames(MarshallerProperties.class); | |
478 | UNMARSHALLER_PROPERTY_NAMES = getPropertyNames(UnmarshallerProperties.class); | |
479 | } | |
480 | ||
481 | @@ -122,7 +115,6 @@ | |
482 | private MoxyJsonConfig getGlobalConfig() { | |
483 | if (globalConfig == null) { | |
484 | globalConfig = new MoxyJsonConfig() | |
485 | - .setContextProperties(getConfigProperties(config, CONTEXT_PROPERTY_NAMES)) | |
486 | .setMarshallerProperties(getConfigProperties(config, MARSHALLER_PROPERTY_NAMES)) | |
487 | .setUnmarshallerProperties(getConfigProperties(config, UNMARSHALLER_PROPERTY_NAMES)); | |
488 | } | |
489 | @@ -161,33 +153,21 @@ | |
490 | } | |
491 | ||
492 | private void initializeUnmarshaller(final Unmarshaller unmarshaller) throws PropertyException { | |
493 | - for (final Map.Entry<String, Object> property : getProperties(PropertiesType.UNMARSHALLER).entrySet()) { | |
494 | + for (final Map.Entry<String, Object> property : getProperties(false).entrySet()) { | |
495 | unmarshaller.setProperty(property.getKey(), property.getValue()); | |
496 | } | |
497 | } | |
498 | ||
499 | private void initializeMarshaller(final Marshaller marshaller) throws PropertyException { | |
500 | - for (final Map.Entry<String, Object> property : getProperties(PropertiesType.MARSHALLER).entrySet()) { | |
501 | + for (final Map.Entry<String, Object> property : getProperties(true).entrySet()) { | |
502 | marshaller.setProperty(property.getKey(), property.getValue()); | |
503 | } | |
504 | } | |
505 | ||
506 | - private Map<String, Object> getProperties(final PropertiesType propertiesType) { | |
507 | + private Map<String, Object> getProperties(final boolean forMarshaller) { | |
508 | + final Map<String, Object> properties = new HashMap<>( | |
509 | + forMarshaller ? getGlobalConfig().getMarshallerProperties() : getGlobalConfig().getUnmarshallerProperties()); | |
510 | ||
511 | - final Map<String, Object> properties = new HashMap<>(); | |
512 | - | |
513 | - switch(propertiesType) { | |
514 | - case MARSHALLER: | |
515 | - properties.putAll(getGlobalConfig().getMarshallerProperties()); | |
516 | - break; | |
517 | - case UNMARSHALLER: | |
518 | - properties.putAll(getGlobalConfig().getUnmarshallerProperties()); | |
519 | - break; | |
520 | - case CONTEXT: | |
521 | - properties.putAll(getGlobalConfig().getContextProperties()); | |
522 | - break; | |
523 | - } | |
524 | - | |
525 | final ContextResolver<MoxyJsonConfig> contextResolver = | |
526 | providers.getContextResolver(MoxyJsonConfig.class, MediaType.APPLICATION_JSON_TYPE); | |
527 | if (contextResolver != null) { | |
528 | @@ -194,17 +174,8 @@ | |
529 | final MoxyJsonConfig jsonConfiguration = contextResolver.getContext(MoxyJsonConfig.class); | |
530 | ||
531 | if (jsonConfiguration != null) { | |
532 | - switch(propertiesType) { | |
533 | - case MARSHALLER: | |
534 | - properties.putAll(jsonConfiguration.getMarshallerProperties()); | |
535 | - break; | |
536 | - case UNMARSHALLER: | |
537 | - properties.putAll(jsonConfiguration.getUnmarshallerProperties()); | |
538 | - break; | |
539 | - case CONTEXT: | |
540 | - properties.putAll(jsonConfiguration.getContextProperties()); | |
541 | - break; | |
542 | - } | |
543 | + properties.putAll(forMarshaller ? | |
544 | + jsonConfiguration.getMarshallerProperties() : jsonConfiguration.getUnmarshallerProperties()); | |
545 | } | |
546 | } | |
547 | ||
548 | @@ -212,11 +183,6 @@ | |
549 | } | |
550 | ||
551 | @Override | |
552 | - protected void overrideContextProperties(Map<String, Object> contextProperties) { | |
553 | - contextProperties.putAll(getProperties(PropertiesType.CONTEXT)); | |
554 | - } | |
555 | - | |
556 | - @Override | |
557 | public boolean isReadable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) { | |
558 | return !isPrimitiveType(type) && !Map.class.isAssignableFrom(type) && super.isReadable(type, genericType, annotations, | |
559 | mediaType); |