@Override public String marshall(Object objectInput) { try { return objectMapper.writeValueAsString(objectInput); } catch (IOException e) { throw new MarshallingException("Error marshalling input", e); } }
@Override public <T> T unmarshall(String serializedInput, Class<T> type) { try { return objectMapper.readValue(serializedInput, type); } catch (IOException e) { throw new MarshallingException("Error unmarshalling input", e); } }
@Override public <T> T unmarshall(String input, Class<T> type) { try { return (T) unmarshaller.unmarshal( new StringReader( input ) ); } catch ( JAXBException e ) { throw new MarshallingException( "Can't unmarshall input string: "+input, e ); } }
public JaxbMarshaller() { try { this.jaxbContext = JAXBContext.newInstance( KIE_SERVER_JAXB_CLASSES ); this.marshaller = jaxbContext.createMarshaller(); this.unmarshaller = jaxbContext.createUnmarshaller(); } catch ( JAXBException e ) { throw new MarshallingException( "Error while creating JAXB context from default classes!", e ); } }
@Override public String marshall(Object input) { StringWriter writer = new StringWriter(); try { marshaller.marshal( input, writer ); } catch ( JAXBException e ) { throw new MarshallingException( "Can't marshall input object: "+input, e ); } return writer.toString(); }
@Override public String marshall(Object objectInput) { try { return objectMapper.writeValueAsString(wrap(objectInput)); } catch (IOException e) { throw new MarshallingException("Error marshalling input", e); } }
@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); } }
protected void buildMarshaller( Set<Class<?>> classes, final ClassLoader classLoader ) { try { logger.debug("Additional classes for JAXB context are {}", classes); Set<Class<?>> allClasses = new HashSet<Class<?>>(); allClasses.addAll(Arrays.asList(KIE_SERVER_JAXB_CLASSES)); if (classes != null) { allClasses.addAll(classes); } logger.debug("All classes for JAXB context are {}", allClasses); this.jaxbContext = JAXBContext.newInstance( allClasses.toArray(new Class[allClasses.size()]) ); } catch ( JAXBException e ) { logger.error("Error while creating JAXB Marshaller due to {}", e.getMessage(), e); throw new MarshallingException( "Error while creating JAXB context from default classes! " + e.getMessage(), e ); } }
@Override public String marshall(Object input) { if (input == null) { return null; } StringWriter writer = new StringWriter(); try { getMarshaller().marshal(ModelWrapper.wrap(input), writer); } catch ( JAXBException e ) { throw new MarshallingException( "Can't marshall input object: "+input, e ); } return writer.toString(); }
@Override public <T> T unmarshall(String input, Class<T> type) { try { return (T) unwrap(getUnmarshaller().unmarshal(new StringReader(input))); } catch ( JAXBException e ) { throw new MarshallingException( "Can't unmarshall input string: "+input, e ); } }