/** * Deserializes a JSON string in {@link #toHawkularFormat(BasicMessage) Hawkular format}. * The JSON object is returned. * * @param nameAndJson the string to be deserialized * @return the object represented by the JSON */ public <T extends BasicMessage> BasicMessageWithExtraData<T> deserialize(String nameAndJson) { String[] nameAndJsonArray = fromHawkularFormat(nameAndJson); String name = nameAndJsonArray[0]; String json = nameAndJsonArray[1]; // The name is the actual name of the POJO that is used to deserialize the JSON. // If not fully qualified with a package then assume it is in our package. if (name.indexOf(".") == -1) { name = String.format("%s.%s", API_PKG, name); } try { Class<T> pojo = (Class<T>) Class.forName(name); return new BasicMessageWithExtraData(AbstractMessage.fromJSON(json, pojo), null); } catch (Exception e) { throw new RuntimeException("Cannot deserialize: [" + nameAndJson + "]", e); } }
throw new IllegalArgumentException("Stream cannot be converted to JSON object of type [" + clazz + "]", e); return new BasicMessageWithExtraData<T>(obj, new BinaryData(remainder, in));
throw new IllegalArgumentException("Stream cannot be converted to JSON object of type [" + clazz + "]", e); return new BasicMessageWithExtraData<T>(obj, new BinaryData(remainder, in));
String receivedBody = ((TextMessage) message).getText(); T basicMessage = AbstractMessage.fromJSON(receivedBody, basicMessageClass); retVal = new BasicMessageWithExtraData<T>(basicMessage, null);
String receivedBody = ((TextMessage) message).getText(); T basicMessage = AbstractMessage.fromJSON(receivedBody, basicMessageClass); retVal = new BasicMessageWithExtraData<T>(basicMessage, null);