@Override public void setProperty(String key, Object value) throws PropertyException { this.jaxbUnmarshaller.setProperty(key, value); }
private void initializeUnmarshaller(final Unmarshaller unmarshaller) throws PropertyException { for (final Map.Entry<String, Object> property : getProperties(false).entrySet()) { unmarshaller.setProperty(property.getKey(), property.getValue()); } }
/** * Template method that can be overridden by concrete JAXB marshallers for custom initialization behavior. * Gets called after creation of JAXB {@code Marshaller}, and after the respective properties have been set. * <p>The default implementation sets the {@link #setUnmarshallerProperties(Map) defined properties}, the {@link * #setValidationEventHandler(ValidationEventHandler) validation event handler}, the {@link #setSchemas(Resource[]) * schemas}, {@link #setUnmarshallerListener(javax.xml.bind.Unmarshaller.Listener) listener}, and * {@link #setAdapters(XmlAdapter[]) adapters}. */ protected void initJaxbUnmarshaller(Unmarshaller unmarshaller) throws JAXBException { if (this.unmarshallerProperties != null) { for (String name : this.unmarshallerProperties.keySet()) { unmarshaller.setProperty(name, this.unmarshallerProperties.get(name)); } } if (this.unmarshallerListener != null) { unmarshaller.setListener(this.unmarshallerListener); } if (this.validationEventHandler != null) { unmarshaller.setEventHandler(this.validationEventHandler); } if (this.adapters != null) { for (XmlAdapter<?, ?> adapter : this.adapters) { unmarshaller.setAdapter(adapter); } } if (this.schema != null) { unmarshaller.setSchema(this.schema); } }
@Override protected void preReadFrom(final Class<Object> type, final Type genericType, final Annotation[] annotations, final MediaType mediaType, final MultivaluedMap<String, String> httpHeaders, final Unmarshaller unmarshaller) throws JAXBException { super.preReadFrom(type, genericType, annotations, mediaType, httpHeaders, unmarshaller); // Entity Filtering. if (unmarshaller.getProperty(MarshallerProperties.OBJECT_GRAPH) == null) { final Object objectGraph = provider.get().getFilteringObject(genericType, false, annotations); if (objectGraph != null) { unmarshaller.setProperty(MarshallerProperties.OBJECT_GRAPH, objectGraph); } } } }
public void setProperty(String s, Object o) throws PropertyException { unmarshaller.setProperty(s, o); }
public void setProperty(String name, Object value) throws PropertyException { delegate.setProperty(name, value); }
public void setProperty(String key, Object value) throws PropertyException { this.jaxbUnmarshaller.setProperty(key, value); }
Class domainClass = getDomainClass(genericType); Unmarshaller u = getJAXBContext(domainClass, mediaType).createUnmarshaller(); u.setProperty("eclipselink.media-type", mediaType.toString()); u.setProperty("eclipselink.json.include-root", false); return u.unmarshal(new StreamSource(entityStream), domainClass).getValue(); } catch(JAXBException jaxbException) {
Class<?> domainClass = getDomainClass(genericType); Unmarshaller u = getJAXBContext(domainClass, mediaType).createUnmarshaller(); u.setProperty("eclipselink.media-type", mediaType.toString()); u.setProperty("eclipselink.json.include-root", false); return u.unmarshal(new StreamSource(entityStream), domainClass).getValue(); } catch(JAXBException jaxbException) {
/** * Delegates to the wrapped unmarshaller. This method is invoked by the parent * class if the given name was not one of the {@link XML} constants. */ @Override void setStandardProperty(final String name, final Object value) throws PropertyException { unmarshaller.setProperty(name, value); }
/** * Delegates to the wrapped unmarshaller. This method is invoked by the parent * class if the given name was not one of the {@link XML} constants. */ @Override void setStandardProperty(final String name, final Object value) throws PropertyException { unmarshaller.setProperty(name, value); }
public void setProperty(String s, Object o) throws PropertyException { unmarshaller.setProperty(s, o); }
public void setProperty(String s, Object o) throws PropertyException { unmarshaller.setProperty(s, o); }
public Object deserialize(Object json, Session session) { try { Unmarshaller unmarshaller = this.context.createUnmarshaller(); unmarshaller.setProperty("eclipselink.media-type", "application/json"); StringReader reader = new StringReader((String)json); return unmarshaller.unmarshal(reader); } catch (JAXBException exception) { throw new RuntimeException(exception); } }
protected Object internalFromXml( final JAXBContext jaxbContext, final String xml, final Map<String, Object> unmarshallerProperties) throws JAXBException { final Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); for (Map.Entry<String, Object> entry : unmarshallerProperties.entrySet()) { unmarshaller.setProperty(entry.getKey(), entry.getValue()); } configure(unmarshaller); return unmarshaller.unmarshal(new StringReader(xml)); }
@SuppressWarnings("unchecked") protected <T> T mapObject(InputStream jsonStream, String mappingFile){ try { ThreadLocal<Unmarshaller> unmarshaller = getCachedUnmarshaller(mappingFile); unmarshaller.get().setProperty(UnmarshallerProperties.JSON_INCLUDE_ROOT, true); return (T) unmarshaller.get().unmarshal(jsonStream); } catch (JAXBException e) { throw new IllegalArgumentException(e); } }
@SuppressWarnings("unchecked") protected <T> T mapObject(InputStream jsonStream, String mappingFile, Class rootClass){ try { ThreadLocal<Unmarshaller> unmarshaller = getCachedUnmarshaller(mappingFile); unmarshaller.get().setProperty(UnmarshallerProperties.JSON_INCLUDE_ROOT, false); return (T) unmarshaller.get().unmarshal(new StreamSource(jsonStream), rootClass).getValue(); } catch (JAXBException e) { throw new IllegalArgumentException(e); } }
@SneakyThrows protected Unmarshaller getUnmarshaller(String mappingFile){ Map<String, Object> properties = new HashMap<>(); properties.put(JAXBContextProperties.OXM_METADATA_SOURCE, mappingFile); properties.put(JAXBContextProperties.MEDIA_TYPE, MediaType.APPLICATION_JSON); ClassLoader classLoader = Thread.currentThread().getContextClassLoader()==null? Account.class.getClassLoader():Thread.currentThread().getContextClassLoader(); JAXBContext jaxbContext = DynamicJAXBContextFactory.createContextFromOXM(classLoader, properties); Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); unmarshaller.setProperty(UnmarshallerProperties.MEDIA_TYPE, MediaType.APPLICATION_JSON); return unmarshaller; }
private void initializeUnmarshaller(final Unmarshaller unmarshaller) throws PropertyException { for (final Map.Entry<String, Object> property : getProperties(false).entrySet()) { unmarshaller.setProperty(property.getKey(), property.getValue()); } }
/** * Acquires a unmarshaller and set the properties to the given value, if non-null. */ final Unmarshaller acquireUnmarshaller(final Map<String,?> properties) throws JAXBException { final Unmarshaller unmarshaller = acquireUnmarshaller(); if (properties != null) { for (final Map.Entry<String,?> entry : properties.entrySet()) { unmarshaller.setProperty(entry.getKey(), entry.getValue()); } } return unmarshaller; }