/** * Marshall an entity to either JSON or XML. * * @param object * @param mediaType * @param output * @param sendRelationships if this is set to true, relationships will be sent as links instead of sending. * the actual objects in the relationships * @throws JAXBException */ @SuppressWarnings({ "rawtypes", "unchecked" }) public void marshall(Object object, MediaType mediaType, OutputStream output, boolean sendRelationships) throws JAXBException { marshall(object, mediaType, output, sendRelationships, null); }
/** * Marshall an entity to either JSON or XML. * * @param object * @param mediaType * @param output * @param sendRelationships if this is set to true, relationships will be sent as links instead of sending. * the actual objects in the relationships * @throws JAXBException */ @SuppressWarnings({ "rawtypes", "unchecked" }) public void marshall(Object object, MediaType mediaType, OutputStream output, boolean sendRelationships) throws JAXBException { marshall(object, mediaType, output, sendRelationships, null); }
/** * Exiting * * @param sourceClass the source class * @param sourceMethod the source method * @param context the context * @param object the object * @param mediaType the media type */ public static void exiting(String sourceClass, String sourceMethod, PersistenceContext context, Object object, MediaType mediaType) { // Log marshaled object only when the log level is FINEST if (logger.isLoggable(Level.FINEST) && (context != null) && (object != null) && (mediaType != null)) { try { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); context.marshall(object, mediaType, outputStream, true); if (object instanceof PersistenceWeavedRest) { exiting(sourceClass, sourceMethod, new Object[] { object.getClass().getName(), outputStream.toString("UTF-8") }); } else { exiting(sourceClass, sourceMethod, new Object[] { outputStream.toString("UTF-8") }); } } catch (Throwable throwable) { } } }
/** * Marshall an entity to either JSON or XML. * * @param object the object to marshal. * @param filter the filter (included/excluded fields) to use. * @param mediaType the media type (XML/JSON). * @param output the result. * @throws JAXBException */ public void marshallEntity(Object object, FieldsFilter filter, MediaType mediaType, OutputStream output) throws JAXBException { JPARSLogger.entering(CLASS_NAME, "marshallEntity", new Object[] { object, filter, mediaType }); marshall(object, mediaType, output, true, filter); JPARSLogger.exiting(CLASS_NAME, "marshallEntity", this, object, mediaType); }
/** * Marshall an entity to either JSON or XML * Calling this method, will treat relationships as unfetched in the XML/JSON and marshall them as links * rather than attempting to marshall the data in those relationships * @param object * @param mediaType * @param output * @throws JAXBException */ public void marshallEntity(Object object, MediaType mediaType, OutputStream output) throws JAXBException { JPARSLogger.entering(CLASS_NAME, "marshallEntity", new Object[] { object, mediaType }); marshall(object, mediaType, output, true); JPARSLogger.exiting(CLASS_NAME, "marshallEntity", this, object, mediaType); }
/** * Exiting * * @param sessionLog the log * @param sourceClass the source class * @param sourceMethod the source method * @param context the context * @param object the object * @param mediaType the media type */ public static void exiting(SessionLog sessionLog, String sourceClass, String sourceMethod, PersistenceContext context, Object object, MediaType mediaType) { // Log marshaled object only when the log level is FINEST if (isLoggableFinest(sessionLog) && (context != null) && (object != null) && (mediaType != null)) { try { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); context.marshall(object, mediaType, outputStream, true); if (object instanceof PersistenceWeavedRest) { exiting(sessionLog, sourceClass, sourceMethod, new Object[] { object.getClass().getName(), outputStream.toString(StandardCharsets.UTF_8.name())}); } else { exiting(sessionLog, sourceClass, sourceMethod, new Object[] { outputStream.toString(StandardCharsets.UTF_8.name()) }); } } catch (Throwable throwable) { exception(throwable.getMessage(), new Object[] {}, throwable); } } }
/** * Marshall an entity to either JSON or XML * Calling this method, will treat relationships as unfetched in the XML/JSON and marshall them as links * rather than attempting to marshall the data in those relationships * @param object * @param mediaType * @param output * @throws JAXBException */ public void marshallEntity(Object object, MediaType mediaType, OutputStream output) throws JAXBException { JPARSLogger.entering(getSessionLog(), CLASS_NAME, "marshallEntity", new Object[] { object, mediaType }); marshall(object, mediaType, output, true); JPARSLogger.exiting(getSessionLog(), CLASS_NAME, "marshallEntity", this, object, mediaType); }
/** * Marshall an entity to either JSON or XML. * * @param object the object to marshal. * @param filter the filter (included/excluded fields) to use. * @param mediaType the media type (XML/JSON). * @param output the result. * @throws JAXBException */ public void marshallEntity(Object object, FieldsFilter filter, MediaType mediaType, OutputStream output) throws JAXBException { JPARSLogger.entering(getSessionLog(), CLASS_NAME, "marshallEntity", new Object[] { object, filter, mediaType }); marshall(object, mediaType, output, true, filter); JPARSLogger.exiting(getSessionLog(), CLASS_NAME, "marshallEntity", this, object, mediaType); }