/** * 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); }
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 ); } }
public Marshaller getMarshaller(MarshallingFormat format) { synchronized ( marshallers ) { Marshaller marshaller = marshallers.get( format ); if ( marshaller == null ) { marshaller = MarshallerFactory.getMarshaller( format, this.kieContainer.getClassLoader() ); this.marshallers.put( format, marshaller ); } return marshaller; } }
public Marshaller getMarshaller(MarshallingFormat format) { synchronized ( marshallers ) { Marshaller marshaller = marshallers.get( format ); if ( marshaller == null ) { marshaller = MarshallerFactory.getMarshaller( getExtraClasses(), format, this.kieContainer.getClassLoader() ); this.marshallers.put( format, marshaller ); } return marshaller; } }
public KieServicesClientImpl(KieServicesConfiguration config) { this.config = config.clone(); this.baseURI = config.getServerUrl(); ClassLoader cl = Thread.currentThread().getContextClassLoader() != null ? Thread.currentThread().getContextClassLoader() : CommandScript.class.getClassLoader(); this.marshaller = MarshallerFactory.getMarshaller( config.getMarshallingFormat(), cl ); }
public String marshal(String marshallingFormat, Object entity) { MarshallingFormat format = getFormat(marshallingFormat); if (format == null) { throw new IllegalArgumentException("Unknown marshalling format " + marshallingFormat); } Marshaller marshaller = serverMarshallers.get(format); if (marshaller == null) { marshaller = MarshallerFactory.getMarshaller(getExtraClasses(registry), format, this.getClass().getClassLoader()); serverMarshallers.put(format, marshaller); } return marshaller.marshall(entity); }
public AbstractKieServicesClientImpl(KieServicesConfiguration config) { this.config = config.clone(); this.loadBalancer = config.getLoadBalancer() == null ? LoadBalancer.getDefault(config.getServerUrl()) : config.getLoadBalancer(); this.classLoader = Thread.currentThread().getContextClassLoader() != null ? Thread.currentThread().getContextClassLoader() : CommandScript.class.getClassLoader(); this.marshaller = MarshallerFactory.getMarshaller(config.getExtraClasses(), config.getMarshallingFormat(), classLoader); this.responseHandler = config.getResponseHandler(); }
@Test public void testMapWithDateJSON() { Marshaller marshaller = MarshallerFactory.getMarshaller(MarshallingFormat.JSON, getClass().getClassLoader()); Map<String, Object> map = new HashMap<>(); map.put("date", new Date()); verifyMarshallingRoundTrip(marshaller, map); }
@Test public void testJaxb() { Marshaller marshaller = MarshallerFactory.getMarshaller(MarshallingFormat.JAXB, getClass().getClassLoader()); verifyMarshallingRoundTrip(marshaller, testObject); }
@Test public void testXStream() { Marshaller marshaller = MarshallerFactory.getMarshaller(MarshallingFormat.XSTREAM, getClass().getClassLoader()); verifyMarshallingRoundTrip(marshaller, testObject); }
@Test public void testJSON() { Marshaller marshaller = MarshallerFactory.getMarshaller(MarshallingFormat.JSON, getClass().getClassLoader()); verifyMarshallingRoundTrip(marshaller, testObject); }
@Test public void testCustomExtensionMarshaller() { Set<Class<?>> extraClasses = new HashSet<Class<?>>(); Marshaller marshaller = MarshallerFactory.getMarshaller(extraClasses, MarshallingFormat.JSON, this.getClass().getClassLoader()); Calendar calendar = GregorianCalendar.getInstance(); String marshall = marshaller.marshall(calendar); assertEquals(marshall, "\""+ FORMATTER.format(calendar.getTime()) +"\"" ); GregorianCalendar unmarshall = marshaller.unmarshall(marshall, GregorianCalendar.class); assertEquals(unmarshall, calendar); }
@Test public void testStringContentMap() { Set<Class<?>> extraClasses = new HashSet<Class<?>>(); Marshaller marshaller = MarshallerFactory.getMarshaller(extraClasses, MarshallingFormat.JSON, this.getClass().getClassLoader()); String jsonMap = "{\"name\" : \"value\"}"; StringContentMap map = new StringContentMap(jsonMap); // content must be of exact value as given in constructor String marshall = marshaller.marshall(map); assertEquals(jsonMap, marshall); }
@Test public void testXStream() { Marshaller marshaller = MarshallerFactory.getMarshaller( getCustomClasses(), MarshallingFormat.XSTREAM, getClass().getClassLoader() ); verifyMarshallingRoundTrip( marshaller, createTestObject() ); }
@Test public void testXStream() { Marshaller marshaller = MarshallerFactory.getMarshaller( getCustomClasses(), MarshallingFormat.XSTREAM, getClass().getClassLoader() ); verifyMarshallingRoundTrip( marshaller, createTestObject() ); }
@Test public void testJSON() { Marshaller marshaller = MarshallerFactory.getMarshaller( getCustomClasses(), MarshallingFormat.JSON, getClass().getClassLoader() ); verifyMarshallingRoundTrip( marshaller, createTestObject() ); }
@Test public void testJaxb() { Marshaller marshaller = MarshallerFactory.getMarshaller( getCustomClasses(), MarshallingFormat.JAXB, getClass().getClassLoader() ); verifyMarshallingRoundTrip( marshaller, createTestObject() ); }
@Test public void testJSON() { Marshaller marshaller = MarshallerFactory.getMarshaller( getCustomClasses(), MarshallingFormat.JSON, getClass().getClassLoader() ); verifyMarshallingRoundTrip( marshaller, createTestObject() ); }
@Test public void testJSON() { Marshaller marshaller = MarshallerFactory.getMarshaller( getCustomClasses(), MarshallingFormat.JSON, getClass().getClassLoader() ); verifyMarshallingRoundTrip( marshaller, createTestObject() ); }
public AbstractKieServicesClientImpl(KieServicesConfiguration config, ClassLoader classLoader) { this.config = config.clone(); this.loadBalancer = config.getLoadBalancer() == null ? LoadBalancer.getDefault(config.getServerUrl()) : config.getLoadBalancer(); this.classLoader = classLoader; this.marshaller = MarshallerFactory.getMarshaller( config.getExtraClasses(), config.getMarshallingFormat(), classLoader ); this.responseHandler = config.getResponseHandler(); }