/** * 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; } }
private <T> T deserialize(String content, Class<T> type) { if (type == null) { return null; } try { return MarshallerFactory.getMarshaller(MarshallingFormat.JSON, this.getClass().getClassLoader()).unmarshall(content, type); } catch ( MarshallingException e ) { throw new IllegalStateException( "Error while deserializing data received from server!", e ); } }
protected void loadDefaultQueryDefinitions() { // load any default query definitions try (InputStream qdStream = this.getClass().getResourceAsStream("/default-query-definitions.json")) { if (qdStream == null) { LOGGER.info("Default query definitions file default-query-definitions.json not found"); return; } loadQueryDefinitions(qdStream, MarshallerFactory.getMarshaller(MarshallingFormat.JSON, this.getClass().getClassLoader())); } catch (Exception e) { LOGGER.error("Error when loading default query definitions from default-query-definitions.json", e); } }
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 <T> T unmarshal(String data, String marshallingFormat, Class<T> unmarshalType) { if (data == null || data.isEmpty()) { return null; } MarshallingFormat format = getFormat(marshallingFormat); Marshaller marshaller = serverMarshallers.get(format); if (marshaller == null) { marshaller = MarshallerFactory.getMarshaller(getExtraClasses(registry), format, this.getClass().getClassLoader()); serverMarshallers.put(format, marshaller); } Object instance = marshaller.unmarshall(data, unmarshalType); if (instance instanceof Wrapped) { return (T) ((Wrapped) instance).unwrap(); } return (T) instance; }
public WebSocketKieServerControllerImpl() { this.marshaller = MarshallerFactory.getMarshaller(MarshallingFormat.JSON, this.getClass().getClassLoader()); this.client = new KieServerMessageHandlerWebSocketClient((WebSocketClient client) -> { try { ((KieServerMessageHandlerWebSocketClient) client).sendTextWithInternalHandler(serialize(serverInfo), new WebSocketKieServerControllerReconnectHandler(context)); } catch (IOException e) { logger.warn("Error when trying to reconnect to Web Socket server - {}", e.getMessage()); } }); }
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(); }
private String toXML(Object pojo, Class<?>... classes) throws Exception { Marshaller marshaller = MarshallerFactory.getMarshaller(new HashSet<Class<?>>(Arrays.asList(classes)), MarshallingFormat.JAXB, getClass().getClassLoader()); return marshaller.marshall(pojo); }
@Before public void setUp() { marshaller = MarshallerFactory.getMarshaller(marshallingFormat, Thread.currentThread().getContextClassLoader()); }
@Before public void setUp() { marshaller = MarshallerFactory.getMarshaller(marshallingFormat, Thread.currentThread().getContextClassLoader()); }
@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); }
private Marshaller createMarshaller() { return MarshallerFactory.getMarshaller(new HashSet<>(extraClasses.values()), configuration.getMarshallingFormat(), client.getClassLoader()); }
@Test public void testUnmarshallListContainersCommandWithNoFilter() { String commandString = "<list-containers/>"; Marshaller marshaller = MarshallerFactory.getMarshaller(MarshallingFormat.XSTREAM, getClass().getClassLoader()); ListContainersCommand command = marshaller.unmarshall(commandString, ListContainersCommand.class); // the default ACCEPT_ALL filter should be set Assertions.assertThat(command.getKieContainerResourceFilter()).isEqualTo(KieContainerResourceFilter.ACCEPT_ALL); }