public static Builder copyBuilder(final JettisonConfig jc) { Builder result = new Builder(jc.getNotation()); switch (jc.notation) { case BADGERFISH: result = new Builder(jc.getNotation()); break; case MAPPED_JETTISON: result = new MappedJettisonBuilder(jc.getNotation()); break; } result.copyAttributes(jc); return result; }
/** * Constructs a new immutable {@link JettisonConfig} object based on options set on this Builder * * @return a non-null {@link JettisonConfig} instance */ public JettisonConfig build() { return new JettisonConfig(this); }
/** * A static method for obtaining a builder of {@link JettisonConfig} instance, which will use {@link JettisonConfig.Notation#MAPPED_JETTISON} JSON notation. * After getting the builder, you can set configuration options on it and finally get an immutable {@code JettisonConfig} * instance using the {@link JettisonConfig.Builder#build() } method. * * @return a builder for {@code JettisonConfig} instance */ public static MappedJettisonBuilder mappedJettison() { return new MappedJettisonBuilder(Notation.MAPPED_JETTISON); }
public static ResourceConfig createApp() { return new ResourceConfig() .register(new JettisonFeature()) .packages("org.glassfish.jersey.examples.console"); }
@Override protected final void writeTo(JAXBElement<?> t, MediaType mediaType, Charset c, Marshaller m, OutputStream entityStream) throws JAXBException { JettisonMarshaller jsonMarshaller = JettisonJaxbContext.getJSONMarshaller(m); if (isFormattedOutput()) { jsonMarshaller.setProperty(JettisonMarshaller.FORMATTED, true); } jsonMarshaller.marshallToJSON(t, new OutputStreamWriter(entityStream, c)); } }
@Override protected void writeTo(Object t, MediaType mediaType, Charset c, Marshaller m, OutputStream entityStream) throws JAXBException { JettisonMarshaller jsonMarshaller = JettisonJaxbContext.getJSONMarshaller(m); if (isFormattedOutput()) { jsonMarshaller.setProperty(JettisonMarshaller.FORMATTED, true); } jsonMarshaller.marshallToJSON(t, new OutputStreamWriter(entityStream, c)); } }
@Override protected final JAXBElement<?> readFrom(Class<?> type, MediaType mediaType, Unmarshaller unmarshaller, InputStream entityStream) throws JAXBException { final Charset c = getCharset(mediaType); return JettisonJaxbContext.getJSONUnmarshaller(unmarshaller) .unmarshalJAXBElementFromJSON(new InputStreamReader(entityStream, c), type); }
@Override protected final Object readFrom(Class<Object> type, MediaType mediaType, Unmarshaller u, InputStream entityStream) throws JAXBException { final Charset c = getCharset(mediaType); return JettisonJaxbContext.getJSONUnmarshaller(u) .unmarshalFromJSON(new InputStreamReader(entityStream, c), type); }
@Override protected final XMLStreamReader getXMLStreamReader(Class<?> elementType, MediaType mediaType, Unmarshaller u, InputStream entityStream) throws XMLStreamException { JettisonConfig c = JettisonConfig.DEFAULT; final Charset charset = getCharset(mediaType); if (u instanceof JettisonConfigured) { c = ((JettisonConfigured) u).getJSONConfiguration(); } return Stax2JettisonFactory.createReader(new InputStreamReader(entityStream, charset), c); } }
public static XMLStreamWriter createWriter(final Writer writer, final JettisonConfig config) throws IOException { switch (config.getNotation()) { case BADGERFISH: return new BadgerFishXMLStreamWriter(writer); case MAPPED_JETTISON: Configuration jmConfig; if (null == config.getXml2JsonNs()) { jmConfig = new Configuration(); } else { jmConfig = new Configuration(config.getXml2JsonNs()); } final MappedXMLStreamWriter result = new MappedXMLStreamWriter(new MappedNamespaceConvention(jmConfig), writer); for (String array : config.getArrayElements()) { result.serializeAsArray(array); } return result; default: return null; } }
/** * Create a JSON unmarshaller. * * @return the JSON unmarshaller * * @throws javax.xml.bind.JAXBException if there is an error creating the unmarshaller. */ public org.glassfish.jersey.jettison.JettisonUnmarshaller createJsonUnmarshaller() throws JAXBException { return new JettisonJaxbUnmarshaller(this, getJSONConfiguration()); }
/** * Overrides underlaying createMarshaller method and returns * a marshaller which is capable of JSON serialization. * * @return marshaller instance with JSON capabilities * @throws javax.xml.bind.JAXBException */ @Override public Marshaller createMarshaller() throws JAXBException { return new JettisonJaxbMarshaller(jaxbContext, getJSONConfiguration()); }
/** * A static method for obtaining {@link JettisonConfig} instance with humanReadableFormatting * set according to formatted parameter. * * @param c original instance of {@link JettisonConfig}, can't be null * @return copy of provided {@link JettisonConfig} with humanReadableFormatting set to formatted. * @throws IllegalArgumentException when provided {@code JettisonConfig} is null. */ public static JettisonConfig createJSONConfiguration(final JettisonConfig c) throws IllegalArgumentException { if (c == null) { throw new IllegalArgumentException("JettisonConfig can't be null"); } final Builder b = copyBuilder(c); return b.build(); }
private void copyAttributes(final JettisonConfig jc) { jsonXml2JsonNs.putAll(jc.getXml2JsonNs()); serializeAsArray.addAll(jc.getArrayElements()); } }
/** * A static method for obtaining a builder of {@link JettisonConfig} instance, which will use {@link JettisonConfig.Notation#BADGERFISH} JSON notation. * After getting the builder, you can set configuration options on it and finally get an immutable {@code JettisonConfig} * instance using the {@link JettisonConfig.Builder#build() } method. * * @return a builder for {@code JettisonConfig} instance */ public static Builder badgerFish() { return new Builder(Notation.BADGERFISH); }
/** * Add element names to be treated as arrays. * This property is valid for the {@link JettisonConfig.Notation#MAPPED_JETTISON} * notation only. * <p> * Property value is a list of element names that should be treated * as arrays even if only a single item is present. * <p> * The default value is an empty list. * * @param arrays names to be serialized as arrays. * @return updated builder instance. */ public MappedJettisonBuilder serializeAsArray(final String... arrays) { return serializeAsArray(Arrays.asList(arrays)); }
public JaxbContextResolver() throws Exception { this.types = new HashSet<Class<?>>(Arrays.asList(cTypes)); this.context = new JettisonJaxbContext(JettisonConfig.DEFAULT, cTypes); }
public static ResourceConfig createApp() { return new ResourceConfig() .register(new JettisonFeature()) .packages("org.glassfish.jersey.examples.jettison"); } }
/** * Overrides underlying createUnmarshaller method and returns * an unmarshaller which is capable of JSON deserialization. * * @return unmarshaller instance with JSON capabilities * @throws javax.xml.bind.JAXBException */ @Override public Unmarshaller createUnmarshaller() throws JAXBException { return new JettisonJaxbUnmarshaller(jaxbContext, getJSONConfiguration()); }
/** * Create a JSON marshaller. * * @return the JSON marshaller. * * @throws javax.xml.bind.JAXBException if there is an error creating the marshaller. */ public org.glassfish.jersey.jettison.JettisonMarshaller createJsonMarshaller() throws JAXBException { return new JettisonJaxbMarshaller(this, getJSONConfiguration()); }