/** * Builds new marshaller for given format and class loader * @param format marshaller format that marshaller should be built for * @param classLoader classloader to be used by the marshaller * @return new instance of the marshaller */ public static Marshaller getMarshaller(MarshallingFormat format, ClassLoader classLoader) { return getMarshaller(null, format, classLoader); }
/** * Builds new marshaller for given format and class loader * @param classes optional custom classes to be added to marshaller - might be null * @param format marshaller format that marshaller should be built for * @param classLoader classloader to be used by the marshaller * @return new instance of the marshaller */ public static Marshaller getMarshaller(Set<Class<?>> classes, MarshallingFormat format, ClassLoader classLoader) { return builder.build(classes, format, classLoader); }
protected String serialize(Object object) { if (object == null) { return ""; } try { return MarshallerFactory.getMarshaller(MarshallingFormat.JSON, this.getClass().getClassLoader()).marshall(object); } catch ( MarshallingException e ) { throw new IllegalStateException( "Error while serializing request data!", e ); } }
protected <T> T deserialize(String content, Class<T> type) { return marshaller.unmarshall( content, type ); } }
protected String serialize(Object object) { if (object == null) { return ""; } try { return marshaller.marshall(object); } catch ( MarshallingException e ) { throw new IllegalStateException( "Error while serializing request data!", e ); } }
@Override public Marshaller build(Set<Class<?>> classes, MarshallingFormat format, ClassLoader classLoader) { if (format.equals(MarshallingFormat.XSTREAM)) { return new XStreamMarshaller(classes, classLoader) { @Override protected void buildMarshaller(Set<Class<?>> classes, ClassLoader classLoader) { xstream = XStreamUtils.createNonTrustingXStream(new PureJavaReflectionProvider(), new DomDriver("UTF-8", new XmlFriendlyNameCoder("_-", "_"))); xstream.addPermission(new WildcardTypePermission(new String[]{"org.kie.server.api.**"})); String[] voidDeny = {"void.class", "Void.class"}; xstream.denyTypes(voidDeny); } }; } return super.build(classes, format, classLoader); } }
public void disposeMarshallers() { synchronized ( marshallers ) { for ( Marshaller marshaller : this.marshallers.values() ) { marshaller.dispose(); } this.marshallers.clear(); } }
public static Object wrap(Object object) { if (object != null && isPrimitiveOrWrapper(object.getClass())) { return wrapPrimitive(object); } return wrapSkipPrimitives(object); }
@Override public String marshall(Object objectInput) { try { return objectMapper.writeValueAsString(objectInput); } catch (IOException e) { throw new MarshallingException("Error marshalling input", e); } }
@Override public ClassLoader getClassLoader() { return this.marshaller.getClassLoader(); }
@Override public void setClassLoader(ClassLoader classLoader) { this.marshaller.setClassLoader(classLoader); }
public JaxbList(List<Object> items) { this.items = items.toArray(); int index = 0; for (Object o : this.items) { this.items[index] = ModelWrapper.wrapSkipPrimitives(o); index++; } }
private <T> T deserialize(String content, Class<T> type) { try { return marshaller.unmarshall( content, type ); } catch ( MarshallingException e ) { throw new KieServicesException( "Error while deserializing data received from server!", e ); } }
protected String serialize(Object object) { if (object == null) { return ""; } try { return marshaller.marshall( object ); } catch ( MarshallingException e ) { throw new KieServicesException( "Error while serializing request data!", e ); } }
public void disposeMarshallers() { synchronized ( marshallers ) { for ( Marshaller marshaller : this.marshallers.values() ) { marshaller.dispose(); } this.marshallers.clear(); } }
@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); } }
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 ); } }