public JSONMarshaller(Set<Class<?>> classes, ClassLoader classLoader) { this.classLoader = classLoader; buildMarshaller(classes, classLoader); configureMarshaller(classes, classLoader); }
@Override public <T> T unmarshall(String serializedInput, Class<T> type) { try { Class actualType = classesSet.contains(type) ? Object.class : type; return (T) unwrap(deserializeObjectMapper.readValue(serializedInput, actualType)); } catch (IOException e) { throw new MarshallingException("Error unmarshalling input", e); } finally { stripped.set(false); } }
@Override public String marshall(Object objectInput) { try { return objectMapper.writeValueAsString(wrap(objectInput)); } catch (IOException e) { throw new MarshallingException("Error marshalling input", e); } }
@Override public Marshaller build(Set<Class<?>> classes, MarshallingFormat format, ClassLoader classLoader) { switch ( format ) { case XSTREAM: logger.debug("About to build default instance of XStream marshaller with classes {} and class loader {}", classes, classLoader); return new XStreamMarshaller( classes, classLoader ); case JAXB: logger.debug("About to build default instance of JAXB marshaller with classes {} and class loader {}", classes, classLoader); return new JaxbMarshaller(classes, classLoader); case JSON: logger.debug("About to build default instance of JSON marshaller with classes {} and class loader {}", classes, classLoader); return new JSONMarshaller(classes, classLoader); default: logger.error( "Unsupported marshalling format: " + format ); } return null; } }
List<NamedType> customClasses = prepareCustomClasses(classes);
public static Marshaller getMarshaller(MarshallingFormat format, ClassLoader classLoader) { switch ( format ) { case XSTREAM: return new XStreamMarshaller( classLoader ); case JAXB: return new JaxbMarshaller(); // has to be implemented case JSON: return new JSONMarshaller(); // has to be implemented default: logger.error( "Unsupported marshalling format: " + format ); } return null; } }