This is an automated email from the ASF dual-hosted git repository.
jamesbognar pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/juneau.git
The following commit(s) were added to refs/heads/master by this push:
new a2842375f JUNEAU-213 Simplified to/from methods for data conversion
a2842375f is described below
commit a2842375fd158dcdfba0a95a7c9cc95e4032cfd4
Author: JamesBognar <[email protected]>
AuthorDate: Fri Jun 24 15:14:39 2022 -0400
JUNEAU-213 Simplified to/from methods for data conversion
---
.../main/java/org/apache/juneau/marshall/N3.java | 150 ++++++++++++++++++++
.../java/org/apache/juneau/marshall/NTriple.java | 150 ++++++++++++++++++++
.../java/org/apache/juneau/marshall/RdfXml.java | 150 ++++++++++++++++++++
.../org/apache/juneau/marshall/RdfXmlAbbrev.java | 150 ++++++++++++++++++++
.../java/org/apache/juneau/marshall/Turtle.java | 150 ++++++++++++++++++++
.../org/apache/juneau/marshall/CharMarshall.java | 67 ++++++++-
.../main/java/org/apache/juneau/marshall/Html.java | 151 +++++++++++++++++++++
.../main/java/org/apache/juneau/marshall/Json.java | 151 +++++++++++++++++++++
.../java/org/apache/juneau/marshall/Marshall.java | 124 +++++------------
.../java/org/apache/juneau/marshall/MsgPack.java | 140 +++++++++++++++++++
.../java/org/apache/juneau/marshall/OpenApi.java | 151 +++++++++++++++++++++
.../java/org/apache/juneau/marshall/PlainText.java | 151 +++++++++++++++++++++
.../org/apache/juneau/marshall/SimpleJson.java | 151 +++++++++++++++++++++
.../org/apache/juneau/marshall/StreamMarshall.java | 68 ++++++++++
.../main/java/org/apache/juneau/marshall/Uon.java | 151 +++++++++++++++++++++
.../org/apache/juneau/marshall/UrlEncoding.java | 151 +++++++++++++++++++++
.../main/java/org/apache/juneau/marshall/Xml.java | 151 +++++++++++++++++++++
.../Topics/02.juneau-marshall/03.jm.Marshalls.html | 6 +-
18 files changed, 2267 insertions(+), 96 deletions(-)
diff --git
a/juneau-core/juneau-marshall-rdf/src/main/java/org/apache/juneau/marshall/N3.java
b/juneau-core/juneau-marshall-rdf/src/main/java/org/apache/juneau/marshall/N3.java
index e97f41736..6e1593e98 100644
---
a/juneau-core/juneau-marshall-rdf/src/main/java/org/apache/juneau/marshall/N3.java
+++
b/juneau-core/juneau-marshall-rdf/src/main/java/org/apache/juneau/marshall/N3.java
@@ -12,7 +12,14 @@
//
***************************************************************************************************************************
package org.apache.juneau.marshall;
+import java.io.*;
+import java.lang.reflect.*;
+import java.nio.charset.*;
+
+import org.apache.juneau.*;
import org.apache.juneau.jena.*;
+import org.apache.juneau.parser.*;
+import org.apache.juneau.serializer.*;
/**
* A pairing of a {@link N3Serializer} and {@link N3Parser} into a single
class with convenience read/write methods.
@@ -69,4 +76,147 @@ public class N3 extends CharMarshall {
public N3() {
this(N3Serializer.DEFAULT, N3Parser.DEFAULT);
}
+ /**
+ * Parses an N3 input string to the specified type.
+ *
+ * <p>
+ * A shortcut for calling <c><jsf>DEFAULT</jsf>.read(<jv>input</jv>,
<jv>type</jv>)</c>.
+ *
+ * @param <T> The class type of the object being created.
+ * @param input The input.
+ * @param type The object type to create.
+ * @return The parsed object.
+ * @throws ParseException Malformed input encountered.
+ */
+ public static <T> T from(String input, Class<T> type) throws
ParseException {
+ return DEFAULT.read(input, type);
+ }
+
+ /**
+ * Parses an N3 input object to the specified Java type.
+ *
+ * <p>
+ * A shortcut for calling <c><jsf>DEFAULT</jsf>.read(<jv>input</jv>,
<jv>type</jv>)</c>.
+ *
+ * @param <T> The class type of the object being created.
+ * @param input
+ * The input.
+ * <br>Can be any of the following types:
+ * <ul>
+ * <li><jk>null</jk>
+ * <li>{@link Reader}
+ * <li>{@link CharSequence}
+ * <li>{@link InputStream} containing UTF-8 encoded text
(or charset defined by
+ * {@link
org.apache.juneau.parser.ReaderParser.Builder#streamCharset(Charset)} property
value).
+ * <li><code><jk>byte</jk>[]</code> containing UTF-8
encoded text (or charset defined by
+ * {@link
org.apache.juneau.parser.ReaderParser.Builder#streamCharset(Charset)} property
value).
+ * <li>{@link File} containing system encoded text (or
charset defined by
+ * {@link
org.apache.juneau.parser.ReaderParser.Builder#fileCharset(Charset)} property
value).
+ * </ul>
+ * @param type The object type to create.
+ * @return The parsed object.
+ * @throws ParseException Malformed input encountered.
+ * @throws IOException Thrown by underlying stream.
+ */
+ public static <T> T from(Object input, Class<T> type) throws
ParseException, IOException {
+ return DEFAULT.read(input, type);
+ }
+
+ /**
+ * Parses an N3 input string to the specified Java type.
+ *
+ * <p>
+ * A shortcut for calling <c><jsf>DEFAULT</jsf>.read(<jv>input</jv>,
<jv>type</jv>, <jv>args</jv>)</c>.
+ *
+ * @param <T> The class type of the object to create.
+ * @param input The input.
+ * @param type
+ * The object type to create.
+ * <br>Can be any of the following: {@link ClassMeta}, {@link
Class}, {@link ParameterizedType}, {@link GenericArrayType}
+ * @param args
+ * The type arguments of the class if it's a collection or map.
+ * <br>Can be any of the following: {@link ClassMeta}, {@link
Class}, {@link ParameterizedType}, {@link GenericArrayType}
+ * <br>Ignored if the main type is not a map or collection.
+ * @return The parsed object.
+ * @throws ParseException Malformed input encountered.
+ * @see BeanSession#getClassMeta(Type,Type...) for argument syntax for
maps and collections.
+ */
+ public static <T> T from(String input, Type type, Type...args) throws
ParseException {
+ return DEFAULT.read(input, type, args);
+ }
+
+ /**
+ * Parses an N3 input object to the specified Java type.
+ *
+ * <p>
+ * A shortcut for calling <c><jsf>DEFAULT</jsf>.read(<jv>input</jv>,
<jv>type</jv>, <jv>args</jv>)</c>.
+ *
+ * @param <T> The class type of the object to create.
+ * @param input
+ * The input.
+ * <br>Can be any of the following types:
+ * <ul>
+ * <li><jk>null</jk>
+ * <li>{@link Reader}
+ * <li>{@link CharSequence}
+ * <li>{@link InputStream} containing UTF-8 encoded text
(or charset defined by
+ * {@link
org.apache.juneau.parser.ReaderParser.Builder#streamCharset(Charset)} property
value).
+ * <li><code><jk>byte</jk>[]</code> containing UTF-8
encoded text (or charset defined by
+ * {@link
org.apache.juneau.parser.ReaderParser.Builder#streamCharset(Charset)} property
value).
+ * <li>{@link File} containing system encoded text (or
charset defined by
+ * {@link
org.apache.juneau.parser.ReaderParser.Builder#fileCharset(Charset)} property
value).
+ * </ul>
+ * @param type
+ * The object type to create.
+ * <br>Can be any of the following: {@link ClassMeta}, {@link
Class}, {@link ParameterizedType}, {@link GenericArrayType}
+ * @param args
+ * The type arguments of the class if it's a collection or map.
+ * <br>Can be any of the following: {@link ClassMeta}, {@link
Class}, {@link ParameterizedType}, {@link GenericArrayType}
+ * <br>Ignored if the main type is not a map or collection.
+ * @return The parsed object.
+ * @throws ParseException Malformed input encountered.
+ * @throws IOException Thrown by underlying stream.
+ * @see BeanSession#getClassMeta(Type,Type...) for argument syntax for
maps and collections.
+ */
+ public static <T> T from(Object input, Type type, Type...args) throws
ParseException, IOException {
+ return DEFAULT.read(input, type, args);
+ }
+
+ /**
+ * Serializes a Java object to an N3 string.
+ *
+ * <p>
+ * A shortcut for calling
<c><jsf>DEFAULT</jsf>.write(<jv>object</jv>)</c>.
+ *
+ * @param object The object to serialize.
+ * @return
+ * The serialized object.
+ * @throws SerializeException If a problem occurred trying to convert
the output.
+ */
+ public static String to(Object object) throws SerializeException {
+ return DEFAULT.write(object);
+ }
+
+ /**
+ * Serializes a Java object to an N3 output.
+ *
+ * <p>
+ * A shortcut for calling
<c><jsf>DEFAULT</jsf>.write(<jv>output</jv>)</c>.
+ *
+ * @param object The object to serialize.
+ * @param output
+ * The output object.
+ * <br>Can be any of the following types:
+ * <ul>
+ * <li>{@link Writer}
+ * <li>{@link OutputStream} - Output will be written as
UTF-8 encoded stream.
+ * <li>{@link File} - Output will be written as
system-default encoded stream.
+ * <li>{@link StringBuilder} - Output will be written to
the specified string builder.
+ * </ul>
+ * @throws SerializeException If a problem occurred trying to convert
the output.
+ * @throws IOException Thrown by underlying stream.
+ */
+ public static void to(Object object, Object output) throws
SerializeException, IOException {
+ DEFAULT.write(object, output);
+ }
}
diff --git
a/juneau-core/juneau-marshall-rdf/src/main/java/org/apache/juneau/marshall/NTriple.java
b/juneau-core/juneau-marshall-rdf/src/main/java/org/apache/juneau/marshall/NTriple.java
index 502dd1526..4849aaa16 100644
---
a/juneau-core/juneau-marshall-rdf/src/main/java/org/apache/juneau/marshall/NTriple.java
+++
b/juneau-core/juneau-marshall-rdf/src/main/java/org/apache/juneau/marshall/NTriple.java
@@ -12,7 +12,14 @@
//
***************************************************************************************************************************
package org.apache.juneau.marshall;
+import java.io.*;
+import java.lang.reflect.*;
+import java.nio.charset.*;
+
+import org.apache.juneau.*;
import org.apache.juneau.jena.*;
+import org.apache.juneau.parser.*;
+import org.apache.juneau.serializer.*;
/**
* A pairing of a {@link NTripleSerializer} and {@link NTripleParser} into a
single class with convenience read/write methods.
@@ -69,4 +76,147 @@ public class NTriple extends CharMarshall {
public NTriple() {
this(NTripleSerializer.DEFAULT, NTripleParser.DEFAULT);
}
+ /**
+ * Parses an N-Triple input string to the specified type.
+ *
+ * <p>
+ * A shortcut for calling <c><jsf>DEFAULT</jsf>.read(<jv>input</jv>,
<jv>type</jv>)</c>.
+ *
+ * @param <T> The class type of the object being created.
+ * @param input The input.
+ * @param type The object type to create.
+ * @return The parsed object.
+ * @throws ParseException Malformed input encountered.
+ */
+ public static <T> T from(String input, Class<T> type) throws
ParseException {
+ return DEFAULT.read(input, type);
+ }
+
+ /**
+ * Parses an N-Triple input object to the specified Java type.
+ *
+ * <p>
+ * A shortcut for calling <c><jsf>DEFAULT</jsf>.read(<jv>input</jv>,
<jv>type</jv>)</c>.
+ *
+ * @param <T> The class type of the object being created.
+ * @param input
+ * The input.
+ * <br>Can be any of the following types:
+ * <ul>
+ * <li><jk>null</jk>
+ * <li>{@link Reader}
+ * <li>{@link CharSequence}
+ * <li>{@link InputStream} containing UTF-8 encoded text
(or charset defined by
+ * {@link
org.apache.juneau.parser.ReaderParser.Builder#streamCharset(Charset)} property
value).
+ * <li><code><jk>byte</jk>[]</code> containing UTF-8
encoded text (or charset defined by
+ * {@link
org.apache.juneau.parser.ReaderParser.Builder#streamCharset(Charset)} property
value).
+ * <li>{@link File} containing system encoded text (or
charset defined by
+ * {@link
org.apache.juneau.parser.ReaderParser.Builder#fileCharset(Charset)} property
value).
+ * </ul>
+ * @param type The object type to create.
+ * @return The parsed object.
+ * @throws ParseException Malformed input encountered.
+ * @throws IOException Thrown by underlying stream.
+ */
+ public static <T> T from(Object input, Class<T> type) throws
ParseException, IOException {
+ return DEFAULT.read(input, type);
+ }
+
+ /**
+ * Parses an N-Triple input string to the specified Java type.
+ *
+ * <p>
+ * A shortcut for calling <c><jsf>DEFAULT</jsf>.read(<jv>input</jv>,
<jv>type</jv>, <jv>args</jv>)</c>.
+ *
+ * @param <T> The class type of the object to create.
+ * @param input The input.
+ * @param type
+ * The object type to create.
+ * <br>Can be any of the following: {@link ClassMeta}, {@link
Class}, {@link ParameterizedType}, {@link GenericArrayType}
+ * @param args
+ * The type arguments of the class if it's a collection or map.
+ * <br>Can be any of the following: {@link ClassMeta}, {@link
Class}, {@link ParameterizedType}, {@link GenericArrayType}
+ * <br>Ignored if the main type is not a map or collection.
+ * @return The parsed object.
+ * @throws ParseException Malformed input encountered.
+ * @see BeanSession#getClassMeta(Type,Type...) for argument syntax for
maps and collections.
+ */
+ public static <T> T from(String input, Type type, Type...args) throws
ParseException {
+ return DEFAULT.read(input, type, args);
+ }
+
+ /**
+ * Parses an N-Triple input object to the specified Java type.
+ *
+ * <p>
+ * A shortcut for calling <c><jsf>DEFAULT</jsf>.read(<jv>input</jv>,
<jv>type</jv>, <jv>args</jv>)</c>.
+ *
+ * @param <T> The class type of the object to create.
+ * @param input
+ * The input.
+ * <br>Can be any of the following types:
+ * <ul>
+ * <li><jk>null</jk>
+ * <li>{@link Reader}
+ * <li>{@link CharSequence}
+ * <li>{@link InputStream} containing UTF-8 encoded text
(or charset defined by
+ * {@link
org.apache.juneau.parser.ReaderParser.Builder#streamCharset(Charset)} property
value).
+ * <li><code><jk>byte</jk>[]</code> containing UTF-8
encoded text (or charset defined by
+ * {@link
org.apache.juneau.parser.ReaderParser.Builder#streamCharset(Charset)} property
value).
+ * <li>{@link File} containing system encoded text (or
charset defined by
+ * {@link
org.apache.juneau.parser.ReaderParser.Builder#fileCharset(Charset)} property
value).
+ * </ul>
+ * @param type
+ * The object type to create.
+ * <br>Can be any of the following: {@link ClassMeta}, {@link
Class}, {@link ParameterizedType}, {@link GenericArrayType}
+ * @param args
+ * The type arguments of the class if it's a collection or map.
+ * <br>Can be any of the following: {@link ClassMeta}, {@link
Class}, {@link ParameterizedType}, {@link GenericArrayType}
+ * <br>Ignored if the main type is not a map or collection.
+ * @return The parsed object.
+ * @throws ParseException Malformed input encountered.
+ * @throws IOException Thrown by underlying stream.
+ * @see BeanSession#getClassMeta(Type,Type...) for argument syntax for
maps and collections.
+ */
+ public static <T> T from(Object input, Type type, Type...args) throws
ParseException, IOException {
+ return DEFAULT.read(input, type, args);
+ }
+
+ /**
+ * Serializes a Java object to an N-Triple string.
+ *
+ * <p>
+ * A shortcut for calling
<c><jsf>DEFAULT</jsf>.write(<jv>object</jv>)</c>.
+ *
+ * @param object The object to serialize.
+ * @return
+ * The serialized object.
+ * @throws SerializeException If a problem occurred trying to convert
the output.
+ */
+ public static String to(Object object) throws SerializeException {
+ return DEFAULT.write(object);
+ }
+
+ /**
+ * Serializes a Java object to an N-Triple output.
+ *
+ * <p>
+ * A shortcut for calling
<c><jsf>DEFAULT</jsf>.write(<jv>output</jv>)</c>.
+ *
+ * @param object The object to serialize.
+ * @param output
+ * The output object.
+ * <br>Can be any of the following types:
+ * <ul>
+ * <li>{@link Writer}
+ * <li>{@link OutputStream} - Output will be written as
UTF-8 encoded stream.
+ * <li>{@link File} - Output will be written as
system-default encoded stream.
+ * <li>{@link StringBuilder} - Output will be written to
the specified string builder.
+ * </ul>
+ * @throws SerializeException If a problem occurred trying to convert
the output.
+ * @throws IOException Thrown by underlying stream.
+ */
+ public static void to(Object object, Object output) throws
SerializeException, IOException {
+ DEFAULT.write(object, output);
+ }
}
diff --git
a/juneau-core/juneau-marshall-rdf/src/main/java/org/apache/juneau/marshall/RdfXml.java
b/juneau-core/juneau-marshall-rdf/src/main/java/org/apache/juneau/marshall/RdfXml.java
index 634bfdd50..55e1d2bc7 100644
---
a/juneau-core/juneau-marshall-rdf/src/main/java/org/apache/juneau/marshall/RdfXml.java
+++
b/juneau-core/juneau-marshall-rdf/src/main/java/org/apache/juneau/marshall/RdfXml.java
@@ -12,7 +12,14 @@
//
***************************************************************************************************************************
package org.apache.juneau.marshall;
+import java.io.*;
+import java.lang.reflect.*;
+import java.nio.charset.*;
+
+import org.apache.juneau.*;
import org.apache.juneau.jena.*;
+import org.apache.juneau.parser.*;
+import org.apache.juneau.serializer.*;
/**
* A pairing of a {@link RdfXmlSerializer} and {@link RdfXmlParser} into a
single class with convenience read/write methods.
@@ -69,4 +76,147 @@ public class RdfXml extends CharMarshall {
public RdfXml() {
this(RdfXmlSerializer.DEFAULT, RdfXmlParser.DEFAULT);
}
+ /**
+ * Parses an RDF/XML input string to the specified type.
+ *
+ * <p>
+ * A shortcut for calling <c><jsf>DEFAULT</jsf>.read(<jv>input</jv>,
<jv>type</jv>)</c>.
+ *
+ * @param <T> The class type of the object being created.
+ * @param input The input.
+ * @param type The object type to create.
+ * @return The parsed object.
+ * @throws ParseException Malformed input encountered.
+ */
+ public static <T> T from(String input, Class<T> type) throws
ParseException {
+ return DEFAULT.read(input, type);
+ }
+
+ /**
+ * Parses an RDF/XML input object to the specified Java type.
+ *
+ * <p>
+ * A shortcut for calling <c><jsf>DEFAULT</jsf>.read(<jv>input</jv>,
<jv>type</jv>)</c>.
+ *
+ * @param <T> The class type of the object being created.
+ * @param input
+ * The input.
+ * <br>Can be any of the following types:
+ * <ul>
+ * <li><jk>null</jk>
+ * <li>{@link Reader}
+ * <li>{@link CharSequence}
+ * <li>{@link InputStream} containing UTF-8 encoded text
(or charset defined by
+ * {@link
org.apache.juneau.parser.ReaderParser.Builder#streamCharset(Charset)} property
value).
+ * <li><code><jk>byte</jk>[]</code> containing UTF-8
encoded text (or charset defined by
+ * {@link
org.apache.juneau.parser.ReaderParser.Builder#streamCharset(Charset)} property
value).
+ * <li>{@link File} containing system encoded text (or
charset defined by
+ * {@link
org.apache.juneau.parser.ReaderParser.Builder#fileCharset(Charset)} property
value).
+ * </ul>
+ * @param type The object type to create.
+ * @return The parsed object.
+ * @throws ParseException Malformed input encountered.
+ * @throws IOException Thrown by underlying stream.
+ */
+ public static <T> T from(Object input, Class<T> type) throws
ParseException, IOException {
+ return DEFAULT.read(input, type);
+ }
+
+ /**
+ * Parses an RDF/XML input string to the specified Java type.
+ *
+ * <p>
+ * A shortcut for calling <c><jsf>DEFAULT</jsf>.read(<jv>input</jv>,
<jv>type</jv>, <jv>args</jv>)</c>.
+ *
+ * @param <T> The class type of the object to create.
+ * @param input The input.
+ * @param type
+ * The object type to create.
+ * <br>Can be any of the following: {@link ClassMeta}, {@link
Class}, {@link ParameterizedType}, {@link GenericArrayType}
+ * @param args
+ * The type arguments of the class if it's a collection or map.
+ * <br>Can be any of the following: {@link ClassMeta}, {@link
Class}, {@link ParameterizedType}, {@link GenericArrayType}
+ * <br>Ignored if the main type is not a map or collection.
+ * @return The parsed object.
+ * @throws ParseException Malformed input encountered.
+ * @see BeanSession#getClassMeta(Type,Type...) for argument syntax for
maps and collections.
+ */
+ public static <T> T from(String input, Type type, Type...args) throws
ParseException {
+ return DEFAULT.read(input, type, args);
+ }
+
+ /**
+ * Parses an RDF/XML input object to the specified Java type.
+ *
+ * <p>
+ * A shortcut for calling <c><jsf>DEFAULT</jsf>.read(<jv>input</jv>,
<jv>type</jv>, <jv>args</jv>)</c>.
+ *
+ * @param <T> The class type of the object to create.
+ * @param input
+ * The input.
+ * <br>Can be any of the following types:
+ * <ul>
+ * <li><jk>null</jk>
+ * <li>{@link Reader}
+ * <li>{@link CharSequence}
+ * <li>{@link InputStream} containing UTF-8 encoded text
(or charset defined by
+ * {@link
org.apache.juneau.parser.ReaderParser.Builder#streamCharset(Charset)} property
value).
+ * <li><code><jk>byte</jk>[]</code> containing UTF-8
encoded text (or charset defined by
+ * {@link
org.apache.juneau.parser.ReaderParser.Builder#streamCharset(Charset)} property
value).
+ * <li>{@link File} containing system encoded text (or
charset defined by
+ * {@link
org.apache.juneau.parser.ReaderParser.Builder#fileCharset(Charset)} property
value).
+ * </ul>
+ * @param type
+ * The object type to create.
+ * <br>Can be any of the following: {@link ClassMeta}, {@link
Class}, {@link ParameterizedType}, {@link GenericArrayType}
+ * @param args
+ * The type arguments of the class if it's a collection or map.
+ * <br>Can be any of the following: {@link ClassMeta}, {@link
Class}, {@link ParameterizedType}, {@link GenericArrayType}
+ * <br>Ignored if the main type is not a map or collection.
+ * @return The parsed object.
+ * @throws ParseException Malformed input encountered.
+ * @throws IOException Thrown by underlying stream.
+ * @see BeanSession#getClassMeta(Type,Type...) for argument syntax for
maps and collections.
+ */
+ public static <T> T from(Object input, Type type, Type...args) throws
ParseException, IOException {
+ return DEFAULT.read(input, type, args);
+ }
+
+ /**
+ * Serializes a Java object to an RDF/XML string.
+ *
+ * <p>
+ * A shortcut for calling
<c><jsf>DEFAULT</jsf>.write(<jv>object</jv>)</c>.
+ *
+ * @param object The object to serialize.
+ * @return
+ * The serialized object.
+ * @throws SerializeException If a problem occurred trying to convert
the output.
+ */
+ public static String to(Object object) throws SerializeException {
+ return DEFAULT.write(object);
+ }
+
+ /**
+ * Serializes a Java object to an RDF/XML output.
+ *
+ * <p>
+ * A shortcut for calling
<c><jsf>DEFAULT</jsf>.write(<jv>output</jv>)</c>.
+ *
+ * @param object The object to serialize.
+ * @param output
+ * The output object.
+ * <br>Can be any of the following types:
+ * <ul>
+ * <li>{@link Writer}
+ * <li>{@link OutputStream} - Output will be written as
UTF-8 encoded stream.
+ * <li>{@link File} - Output will be written as
system-default encoded stream.
+ * <li>{@link StringBuilder} - Output will be written to
the specified string builder.
+ * </ul>
+ * @throws SerializeException If a problem occurred trying to convert
the output.
+ * @throws IOException Thrown by underlying stream.
+ */
+ public static void to(Object object, Object output) throws
SerializeException, IOException {
+ DEFAULT.write(object, output);
+ }
}
diff --git
a/juneau-core/juneau-marshall-rdf/src/main/java/org/apache/juneau/marshall/RdfXmlAbbrev.java
b/juneau-core/juneau-marshall-rdf/src/main/java/org/apache/juneau/marshall/RdfXmlAbbrev.java
index c3438846f..608f3e4b7 100644
---
a/juneau-core/juneau-marshall-rdf/src/main/java/org/apache/juneau/marshall/RdfXmlAbbrev.java
+++
b/juneau-core/juneau-marshall-rdf/src/main/java/org/apache/juneau/marshall/RdfXmlAbbrev.java
@@ -12,7 +12,14 @@
//
***************************************************************************************************************************
package org.apache.juneau.marshall;
+import java.io.*;
+import java.lang.reflect.*;
+import java.nio.charset.*;
+
+import org.apache.juneau.*;
import org.apache.juneau.jena.*;
+import org.apache.juneau.parser.*;
+import org.apache.juneau.serializer.*;
/**
* A pairing of a {@link RdfXmlAbbrevSerializer} and {@link RdfXmlParser} into
a single class with convenience read/write methods.
@@ -69,4 +76,147 @@ public class RdfXmlAbbrev extends CharMarshall {
public RdfXmlAbbrev() {
this(RdfXmlAbbrevSerializer.DEFAULT, RdfXmlParser.DEFAULT);
}
+ /**
+ * Parses an Abbreviated RDF/XML input string to the specified type.
+ *
+ * <p>
+ * A shortcut for calling <c><jsf>DEFAULT</jsf>.read(<jv>input</jv>,
<jv>type</jv>)</c>.
+ *
+ * @param <T> The class type of the object being created.
+ * @param input The input.
+ * @param type The object type to create.
+ * @return The parsed object.
+ * @throws ParseException Malformed input encountered.
+ */
+ public static <T> T from(String input, Class<T> type) throws
ParseException {
+ return DEFAULT.read(input, type);
+ }
+
+ /**
+ * Parses an Abbreviated RDF/XML input object to the specified Java
type.
+ *
+ * <p>
+ * A shortcut for calling <c><jsf>DEFAULT</jsf>.read(<jv>input</jv>,
<jv>type</jv>)</c>.
+ *
+ * @param <T> The class type of the object being created.
+ * @param input
+ * The input.
+ * <br>Can be any of the following types:
+ * <ul>
+ * <li><jk>null</jk>
+ * <li>{@link Reader}
+ * <li>{@link CharSequence}
+ * <li>{@link InputStream} containing UTF-8 encoded text
(or charset defined by
+ * {@link
org.apache.juneau.parser.ReaderParser.Builder#streamCharset(Charset)} property
value).
+ * <li><code><jk>byte</jk>[]</code> containing UTF-8
encoded text (or charset defined by
+ * {@link
org.apache.juneau.parser.ReaderParser.Builder#streamCharset(Charset)} property
value).
+ * <li>{@link File} containing system encoded text (or
charset defined by
+ * {@link
org.apache.juneau.parser.ReaderParser.Builder#fileCharset(Charset)} property
value).
+ * </ul>
+ * @param type The object type to create.
+ * @return The parsed object.
+ * @throws ParseException Malformed input encountered.
+ * @throws IOException Thrown by underlying stream.
+ */
+ public static <T> T from(Object input, Class<T> type) throws
ParseException, IOException {
+ return DEFAULT.read(input, type);
+ }
+
+ /**
+ * Parses an Abbreviated RDF/XML input string to the specified Java
type.
+ *
+ * <p>
+ * A shortcut for calling <c><jsf>DEFAULT</jsf>.read(<jv>input</jv>,
<jv>type</jv>, <jv>args</jv>)</c>.
+ *
+ * @param <T> The class type of the object to create.
+ * @param input The input.
+ * @param type
+ * The object type to create.
+ * <br>Can be any of the following: {@link ClassMeta}, {@link
Class}, {@link ParameterizedType}, {@link GenericArrayType}
+ * @param args
+ * The type arguments of the class if it's a collection or map.
+ * <br>Can be any of the following: {@link ClassMeta}, {@link
Class}, {@link ParameterizedType}, {@link GenericArrayType}
+ * <br>Ignored if the main type is not a map or collection.
+ * @return The parsed object.
+ * @throws ParseException Malformed input encountered.
+ * @see BeanSession#getClassMeta(Type,Type...) for argument syntax for
maps and collections.
+ */
+ public static <T> T from(String input, Type type, Type...args) throws
ParseException {
+ return DEFAULT.read(input, type, args);
+ }
+
+ /**
+ * Parses an Abbreviated RDF/XML input object to the specified Java
type.
+ *
+ * <p>
+ * A shortcut for calling <c><jsf>DEFAULT</jsf>.read(<jv>input</jv>,
<jv>type</jv>, <jv>args</jv>)</c>.
+ *
+ * @param <T> The class type of the object to create.
+ * @param input
+ * The input.
+ * <br>Can be any of the following types:
+ * <ul>
+ * <li><jk>null</jk>
+ * <li>{@link Reader}
+ * <li>{@link CharSequence}
+ * <li>{@link InputStream} containing UTF-8 encoded text
(or charset defined by
+ * {@link
org.apache.juneau.parser.ReaderParser.Builder#streamCharset(Charset)} property
value).
+ * <li><code><jk>byte</jk>[]</code> containing UTF-8
encoded text (or charset defined by
+ * {@link
org.apache.juneau.parser.ReaderParser.Builder#streamCharset(Charset)} property
value).
+ * <li>{@link File} containing system encoded text (or
charset defined by
+ * {@link
org.apache.juneau.parser.ReaderParser.Builder#fileCharset(Charset)} property
value).
+ * </ul>
+ * @param type
+ * The object type to create.
+ * <br>Can be any of the following: {@link ClassMeta}, {@link
Class}, {@link ParameterizedType}, {@link GenericArrayType}
+ * @param args
+ * The type arguments of the class if it's a collection or map.
+ * <br>Can be any of the following: {@link ClassMeta}, {@link
Class}, {@link ParameterizedType}, {@link GenericArrayType}
+ * <br>Ignored if the main type is not a map or collection.
+ * @return The parsed object.
+ * @throws ParseException Malformed input encountered.
+ * @throws IOException Thrown by underlying stream.
+ * @see BeanSession#getClassMeta(Type,Type...) for argument syntax for
maps and collections.
+ */
+ public static <T> T from(Object input, Type type, Type...args) throws
ParseException, IOException {
+ return DEFAULT.read(input, type, args);
+ }
+
+ /**
+ * Serializes a Java object to an Abbreviated RDF/XML string.
+ *
+ * <p>
+ * A shortcut for calling
<c><jsf>DEFAULT</jsf>.write(<jv>object</jv>)</c>.
+ *
+ * @param object The object to serialize.
+ * @return
+ * The serialized object.
+ * @throws SerializeException If a problem occurred trying to convert
the output.
+ */
+ public static String to(Object object) throws SerializeException {
+ return DEFAULT.write(object);
+ }
+
+ /**
+ * Serializes a Java object to an Abbreviated RDF/XML output.
+ *
+ * <p>
+ * A shortcut for calling
<c><jsf>DEFAULT</jsf>.write(<jv>output</jv>)</c>.
+ *
+ * @param object The object to serialize.
+ * @param output
+ * The output object.
+ * <br>Can be any of the following types:
+ * <ul>
+ * <li>{@link Writer}
+ * <li>{@link OutputStream} - Output will be written as
UTF-8 encoded stream.
+ * <li>{@link File} - Output will be written as
system-default encoded stream.
+ * <li>{@link StringBuilder} - Output will be written to
the specified string builder.
+ * </ul>
+ * @throws SerializeException If a problem occurred trying to convert
the output.
+ * @throws IOException Thrown by underlying stream.
+ */
+ public static void to(Object object, Object output) throws
SerializeException, IOException {
+ DEFAULT.write(object, output);
+ }
}
diff --git
a/juneau-core/juneau-marshall-rdf/src/main/java/org/apache/juneau/marshall/Turtle.java
b/juneau-core/juneau-marshall-rdf/src/main/java/org/apache/juneau/marshall/Turtle.java
index 25720a597..1718acfe8 100644
---
a/juneau-core/juneau-marshall-rdf/src/main/java/org/apache/juneau/marshall/Turtle.java
+++
b/juneau-core/juneau-marshall-rdf/src/main/java/org/apache/juneau/marshall/Turtle.java
@@ -12,7 +12,14 @@
//
***************************************************************************************************************************
package org.apache.juneau.marshall;
+import java.io.*;
+import java.lang.reflect.*;
+import java.nio.charset.*;
+
+import org.apache.juneau.*;
import org.apache.juneau.jena.*;
+import org.apache.juneau.parser.*;
+import org.apache.juneau.serializer.*;
/**
* A pairing of a {@link TurtleSerializer} and {@link TurtleParser} into a
single class with convenience read/write methods.
@@ -69,4 +76,147 @@ public class Turtle extends CharMarshall {
public Turtle() {
this(TurtleSerializer.DEFAULT, TurtleParser.DEFAULT);
}
+ /**
+ * Parses a Turtle input string to the specified type.
+ *
+ * <p>
+ * A shortcut for calling <c><jsf>DEFAULT</jsf>.read(<jv>input</jv>,
<jv>type</jv>)</c>.
+ *
+ * @param <T> The class type of the object being created.
+ * @param input The input.
+ * @param type The object type to create.
+ * @return The parsed object.
+ * @throws ParseException Malformed input encountered.
+ */
+ public static <T> T from(String input, Class<T> type) throws
ParseException {
+ return DEFAULT.read(input, type);
+ }
+
+ /**
+ * Parses a Turtle input object to the specified Java type.
+ *
+ * <p>
+ * A shortcut for calling <c><jsf>DEFAULT</jsf>.read(<jv>input</jv>,
<jv>type</jv>)</c>.
+ *
+ * @param <T> The class type of the object being created.
+ * @param input
+ * The input.
+ * <br>Can be any of the following types:
+ * <ul>
+ * <li><jk>null</jk>
+ * <li>{@link Reader}
+ * <li>{@link CharSequence}
+ * <li>{@link InputStream} containing UTF-8 encoded text
(or charset defined by
+ * {@link
org.apache.juneau.parser.ReaderParser.Builder#streamCharset(Charset)} property
value).
+ * <li><code><jk>byte</jk>[]</code> containing UTF-8
encoded text (or charset defined by
+ * {@link
org.apache.juneau.parser.ReaderParser.Builder#streamCharset(Charset)} property
value).
+ * <li>{@link File} containing system encoded text (or
charset defined by
+ * {@link
org.apache.juneau.parser.ReaderParser.Builder#fileCharset(Charset)} property
value).
+ * </ul>
+ * @param type The object type to create.
+ * @return The parsed object.
+ * @throws ParseException Malformed input encountered.
+ * @throws IOException Thrown by underlying stream.
+ */
+ public static <T> T from(Object input, Class<T> type) throws
ParseException, IOException {
+ return DEFAULT.read(input, type);
+ }
+
+ /**
+ * Parses a Turtle input string to the specified Java type.
+ *
+ * <p>
+ * A shortcut for calling <c><jsf>DEFAULT</jsf>.read(<jv>input</jv>,
<jv>type</jv>, <jv>args</jv>)</c>.
+ *
+ * @param <T> The class type of the object to create.
+ * @param input The input.
+ * @param type
+ * The object type to create.
+ * <br>Can be any of the following: {@link ClassMeta}, {@link
Class}, {@link ParameterizedType}, {@link GenericArrayType}
+ * @param args
+ * The type arguments of the class if it's a collection or map.
+ * <br>Can be any of the following: {@link ClassMeta}, {@link
Class}, {@link ParameterizedType}, {@link GenericArrayType}
+ * <br>Ignored if the main type is not a map or collection.
+ * @return The parsed object.
+ * @throws ParseException Malformed input encountered.
+ * @see BeanSession#getClassMeta(Type,Type...) for argument syntax for
maps and collections.
+ */
+ public static <T> T from(String input, Type type, Type...args) throws
ParseException {
+ return DEFAULT.read(input, type, args);
+ }
+
+ /**
+ * Parses a Turtle input object to the specified Java type.
+ *
+ * <p>
+ * A shortcut for calling <c><jsf>DEFAULT</jsf>.read(<jv>input</jv>,
<jv>type</jv>, <jv>args</jv>)</c>.
+ *
+ * @param <T> The class type of the object to create.
+ * @param input
+ * The input.
+ * <br>Can be any of the following types:
+ * <ul>
+ * <li><jk>null</jk>
+ * <li>{@link Reader}
+ * <li>{@link CharSequence}
+ * <li>{@link InputStream} containing UTF-8 encoded text
(or charset defined by
+ * {@link
org.apache.juneau.parser.ReaderParser.Builder#streamCharset(Charset)} property
value).
+ * <li><code><jk>byte</jk>[]</code> containing UTF-8
encoded text (or charset defined by
+ * {@link
org.apache.juneau.parser.ReaderParser.Builder#streamCharset(Charset)} property
value).
+ * <li>{@link File} containing system encoded text (or
charset defined by
+ * {@link
org.apache.juneau.parser.ReaderParser.Builder#fileCharset(Charset)} property
value).
+ * </ul>
+ * @param type
+ * The object type to create.
+ * <br>Can be any of the following: {@link ClassMeta}, {@link
Class}, {@link ParameterizedType}, {@link GenericArrayType}
+ * @param args
+ * The type arguments of the class if it's a collection or map.
+ * <br>Can be any of the following: {@link ClassMeta}, {@link
Class}, {@link ParameterizedType}, {@link GenericArrayType}
+ * <br>Ignored if the main type is not a map or collection.
+ * @return The parsed object.
+ * @throws ParseException Malformed input encountered.
+ * @throws IOException Thrown by underlying stream.
+ * @see BeanSession#getClassMeta(Type,Type...) for argument syntax for
maps and collections.
+ */
+ public static <T> T from(Object input, Type type, Type...args) throws
ParseException, IOException {
+ return DEFAULT.read(input, type, args);
+ }
+
+ /**
+ * Serializes a Java object to a Turtle string.
+ *
+ * <p>
+ * A shortcut for calling
<c><jsf>DEFAULT</jsf>.write(<jv>object</jv>)</c>.
+ *
+ * @param object The object to serialize.
+ * @return
+ * The serialized object.
+ * @throws SerializeException If a problem occurred trying to convert
the output.
+ */
+ public static String to(Object object) throws SerializeException {
+ return DEFAULT.write(object);
+ }
+
+ /**
+ * Serializes a Java object to a Turtle output.
+ *
+ * <p>
+ * A shortcut for calling
<c><jsf>DEFAULT</jsf>.write(<jv>output</jv>)</c>.
+ *
+ * @param object The object to serialize.
+ * @param output
+ * The output object.
+ * <br>Can be any of the following types:
+ * <ul>
+ * <li>{@link Writer}
+ * <li>{@link OutputStream} - Output will be written as
UTF-8 encoded stream.
+ * <li>{@link File} - Output will be written as
system-default encoded stream.
+ * <li>{@link StringBuilder} - Output will be written to
the specified string builder.
+ * </ul>
+ * @throws SerializeException If a problem occurred trying to convert
the output.
+ * @throws IOException Thrown by underlying stream.
+ */
+ public static void to(Object object, Object output) throws
SerializeException, IOException {
+ DEFAULT.write(object, output);
+ }
}
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/marshall/CharMarshall.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/marshall/CharMarshall.java
index ba6964b42..fd9917377 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/marshall/CharMarshall.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/marshall/CharMarshall.java
@@ -12,6 +12,9 @@
//
***************************************************************************************************************************
package org.apache.juneau.marshall;
+import java.lang.reflect.*;
+
+import org.apache.juneau.*;
import org.apache.juneau.parser.*;
import org.apache.juneau.serializer.*;
@@ -25,6 +28,7 @@ import org.apache.juneau.serializer.*;
*/
public class CharMarshall extends Marshall {
+ private final ReaderParser p;
private final WriterSerializer s;
/**
@@ -40,18 +44,75 @@ public class CharMarshall extends Marshall {
public CharMarshall(WriterSerializer s, ReaderParser p) {
super(s, p);
this.s = s;
+ this.p = p;
+ }
+
+ /**
+ * Same as {@link #read(Object,Class)} but reads from a string and thus
doesn't throw an <c>IOException</c>.
+ *
+ * <p>
+ * This is the preferred parse method for simple types since you don't
need to cast the results.
+ *
+ * <h5 class='section'>Examples:</h5>
+ * <p class='bjava'>
+ * Marshall <jv>marshall</jv> = Json.<jsf>DEFAULT</jsf>;
+ *
+ * <jc>// Parse into a string.</jc>
+ * String <jv>string</jv> = <jv>marshall</jv>.read(<jv>json</jv>,
String.<jk>class</jk>);
+ *
+ * <jc>// Parse into a bean.</jc>
+ * MyBean <jv>bean</jv> = <jv>marshall</jv>.read(<jv>json</jv>,
MyBean.<jk>class</jk>);
+ *
+ * <jc>// Parse into a bean array.</jc>
+ * MyBean[] <jv>beanArray</jv> =
<jv>marshall</jv>.read(<jv>json</jv>, MyBean[].<jk>class</jk>);
+ *
+ * <jc>// Parse into a linked-list of objects.</jc>
+ * List <jv>list</jv> = <jv>marshall</jv>.read(<jv>json</jv>,
LinkedList.<jk>class</jk>);
+ *
+ * <jc>// Parse into a map of object keys/values.</jc>
+ * Map <jv>map</jv> = <jv>marshall</jv>.read(<jv>json</jv>,
TreeMap.<jk>class</jk>);
+ * </p>
+ *
+ * @param <T> The class type of the object being created.
+ * @param input The input.
+ * @param type The object type to create.
+ * @return The parsed object.
+ * @throws ParseException Malformed input encountered.
+ */
+ public final <T> T read(String input, Class<T> type) throws
ParseException {
+ return p.parse(input, type);
+ }
+
+ /**
+ * Same as {@link #read(Object,Type,Type...)} but reads from a string
and thus doesn't throw an <c>IOException</c>.
+ *
+ * @param <T> The class type of the object to create.
+ * @param input The input.
+ * @param type
+ * The object type to create.
+ * <br>Can be any of the following: {@link ClassMeta}, {@link
Class}, {@link ParameterizedType}, {@link GenericArrayType}
+ * @param args
+ * The type arguments of the class if it's a collection or map.
+ * <br>Can be any of the following: {@link ClassMeta}, {@link
Class}, {@link ParameterizedType}, {@link GenericArrayType}
+ * <br>Ignored if the main type is not a map or collection.
+ * @return The parsed object.
+ * @throws ParseException Malformed input encountered.
+ * @see BeanSession#getClassMeta(Type,Type...) for argument syntax for
maps and collections.
+ */
+ public final <T> T read(String input, Type type, Type...args) throws
ParseException {
+ return p.parse(input, type, args);
}
/**
* Serializes a POJO directly to a <c>String</c>.
*
- * @param o The object to serialize.
+ * @param object The object to serialize.
* @return
* The serialized object.
* @throws SerializeException If a problem occurred trying to convert
the output.
*/
@Override /* Serializer */
- public final String write(Object o) throws SerializeException {
- return s.serializeToString(o);
+ public final String write(Object object) throws SerializeException {
+ return s.serializeToString(object);
}
}
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/marshall/Html.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/marshall/Html.java
index 492970dcc..c03be39fc 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/marshall/Html.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/marshall/Html.java
@@ -12,7 +12,14 @@
//
***************************************************************************************************************************
package org.apache.juneau.marshall;
+import java.io.*;
+import java.lang.reflect.*;
+import java.nio.charset.*;
+
+import org.apache.juneau.*;
import org.apache.juneau.html.*;
+import org.apache.juneau.parser.*;
+import org.apache.juneau.serializer.*;
/**
* A pairing of a {@link HtmlSerializer} and {@link HtmlParser} into a single
class with convenience read/write methods.
@@ -68,4 +75,148 @@ public class Html extends CharMarshall {
public Html() {
this(HtmlSerializer.DEFAULT, HtmlParser.DEFAULT);
}
+
+ /**
+ * Parses an HTML input string to the specified type.
+ *
+ * <p>
+ * A shortcut for calling <c><jsf>DEFAULT</jsf>.read(<jv>input</jv>,
<jv>type</jv>)</c>.
+ *
+ * @param <T> The class type of the object being created.
+ * @param input The input.
+ * @param type The object type to create.
+ * @return The parsed object.
+ * @throws ParseException Malformed input encountered.
+ */
+ public static <T> T from(String input, Class<T> type) throws
ParseException {
+ return DEFAULT.read(input, type);
+ }
+
+ /**
+ * Parses an HTML input object to the specified Java type.
+ *
+ * <p>
+ * A shortcut for calling <c><jsf>DEFAULT</jsf>.read(<jv>input</jv>,
<jv>type</jv>)</c>.
+ *
+ * @param <T> The class type of the object being created.
+ * @param input
+ * The input.
+ * <br>Can be any of the following types:
+ * <ul>
+ * <li><jk>null</jk>
+ * <li>{@link Reader}
+ * <li>{@link CharSequence}
+ * <li>{@link InputStream} containing UTF-8 encoded text
(or charset defined by
+ * {@link
org.apache.juneau.parser.ReaderParser.Builder#streamCharset(Charset)} property
value).
+ * <li><code><jk>byte</jk>[]</code> containing UTF-8
encoded text (or charset defined by
+ * {@link
org.apache.juneau.parser.ReaderParser.Builder#streamCharset(Charset)} property
value).
+ * <li>{@link File} containing system encoded text (or
charset defined by
+ * {@link
org.apache.juneau.parser.ReaderParser.Builder#fileCharset(Charset)} property
value).
+ * </ul>
+ * @param type The object type to create.
+ * @return The parsed object.
+ * @throws ParseException Malformed input encountered.
+ * @throws IOException Thrown by underlying stream.
+ */
+ public static <T> T from(Object input, Class<T> type) throws
ParseException, IOException {
+ return DEFAULT.read(input, type);
+ }
+
+ /**
+ * Parses an HTML input string to the specified Java type.
+ *
+ * <p>
+ * A shortcut for calling <c><jsf>DEFAULT</jsf>.read(<jv>input</jv>,
<jv>type</jv>, <jv>args</jv>)</c>.
+ *
+ * @param <T> The class type of the object to create.
+ * @param input The input.
+ * @param type
+ * The object type to create.
+ * <br>Can be any of the following: {@link ClassMeta}, {@link
Class}, {@link ParameterizedType}, {@link GenericArrayType}
+ * @param args
+ * The type arguments of the class if it's a collection or map.
+ * <br>Can be any of the following: {@link ClassMeta}, {@link
Class}, {@link ParameterizedType}, {@link GenericArrayType}
+ * <br>Ignored if the main type is not a map or collection.
+ * @return The parsed object.
+ * @throws ParseException Malformed input encountered.
+ * @see BeanSession#getClassMeta(Type,Type...) for argument syntax for
maps and collections.
+ */
+ public static <T> T from(String input, Type type, Type...args) throws
ParseException {
+ return DEFAULT.read(input, type, args);
+ }
+
+ /**
+ * Parses an HTML input object to the specified Java type.
+ *
+ * <p>
+ * A shortcut for calling <c><jsf>DEFAULT</jsf>.read(<jv>input</jv>,
<jv>type</jv>, <jv>args</jv>)</c>.
+ *
+ * @param <T> The class type of the object to create.
+ * @param input
+ * The input.
+ * <br>Can be any of the following types:
+ * <ul>
+ * <li><jk>null</jk>
+ * <li>{@link Reader}
+ * <li>{@link CharSequence}
+ * <li>{@link InputStream} containing UTF-8 encoded text
(or charset defined by
+ * {@link
org.apache.juneau.parser.ReaderParser.Builder#streamCharset(Charset)} property
value).
+ * <li><code><jk>byte</jk>[]</code> containing UTF-8
encoded text (or charset defined by
+ * {@link
org.apache.juneau.parser.ReaderParser.Builder#streamCharset(Charset)} property
value).
+ * <li>{@link File} containing system encoded text (or
charset defined by
+ * {@link
org.apache.juneau.parser.ReaderParser.Builder#fileCharset(Charset)} property
value).
+ * </ul>
+ * @param type
+ * The object type to create.
+ * <br>Can be any of the following: {@link ClassMeta}, {@link
Class}, {@link ParameterizedType}, {@link GenericArrayType}
+ * @param args
+ * The type arguments of the class if it's a collection or map.
+ * <br>Can be any of the following: {@link ClassMeta}, {@link
Class}, {@link ParameterizedType}, {@link GenericArrayType}
+ * <br>Ignored if the main type is not a map or collection.
+ * @return The parsed object.
+ * @throws ParseException Malformed input encountered.
+ * @throws IOException Thrown by underlying stream.
+ * @see BeanSession#getClassMeta(Type,Type...) for argument syntax for
maps and collections.
+ */
+ public static <T> T from(Object input, Type type, Type...args) throws
ParseException, IOException {
+ return DEFAULT.read(input, type, args);
+ }
+
+ /**
+ * Serializes a Java object to an HTML string.
+ *
+ * <p>
+ * A shortcut for calling
<c><jsf>DEFAULT</jsf>.write(<jv>object</jv>)</c>.
+ *
+ * @param object The object to serialize.
+ * @return
+ * The serialized object.
+ * @throws SerializeException If a problem occurred trying to convert
the output.
+ */
+ public static String to(Object object) throws SerializeException {
+ return DEFAULT.write(object);
+ }
+
+ /**
+ * Serializes a Java object to an HTML output.
+ *
+ * <p>
+ * A shortcut for calling
<c><jsf>DEFAULT</jsf>.write(<jv>output</jv>)</c>.
+ *
+ * @param object The object to serialize.
+ * @param output
+ * The output object.
+ * <br>Can be any of the following types:
+ * <ul>
+ * <li>{@link Writer}
+ * <li>{@link OutputStream} - Output will be written as
UTF-8 encoded stream.
+ * <li>{@link File} - Output will be written as
system-default encoded stream.
+ * <li>{@link StringBuilder} - Output will be written to
the specified string builder.
+ * </ul>
+ * @throws SerializeException If a problem occurred trying to convert
the output.
+ * @throws IOException Thrown by underlying stream.
+ */
+ public static void to(Object object, Object output) throws
SerializeException, IOException {
+ DEFAULT.write(object, output);
+ }
}
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/marshall/Json.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/marshall/Json.java
index 8652ed5a9..980f807f3 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/marshall/Json.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/marshall/Json.java
@@ -12,7 +12,14 @@
//
***************************************************************************************************************************
package org.apache.juneau.marshall;
+import java.io.*;
+import java.lang.reflect.*;
+import java.nio.charset.*;
+
+import org.apache.juneau.*;
import org.apache.juneau.json.*;
+import org.apache.juneau.parser.*;
+import org.apache.juneau.serializer.*;
/**
* A pairing of a {@link JsonSerializer} and {@link JsonParser} into a single
class with convenience read/write methods.
@@ -68,4 +75,148 @@ public class Json extends CharMarshall {
public Json() {
this(JsonSerializer.DEFAULT, JsonParser.DEFAULT);
}
+
+ /**
+ * Parses a JSON input string to the specified type.
+ *
+ * <p>
+ * A shortcut for calling <c><jsf>DEFAULT</jsf>.read(<jv>input</jv>,
<jv>type</jv>)</c>.
+ *
+ * @param <T> The class type of the object being created.
+ * @param input The input.
+ * @param type The object type to create.
+ * @return The parsed object.
+ * @throws ParseException Malformed input encountered.
+ */
+ public static <T> T from(String input, Class<T> type) throws
ParseException {
+ return DEFAULT.read(input, type);
+ }
+
+ /**
+ * Parses a JSON input object to the specified Java type.
+ *
+ * <p>
+ * A shortcut for calling <c><jsf>DEFAULT</jsf>.read(<jv>input</jv>,
<jv>type</jv>)</c>.
+ *
+ * @param <T> The class type of the object being created.
+ * @param input
+ * The input.
+ * <br>Can be any of the following types:
+ * <ul>
+ * <li><jk>null</jk>
+ * <li>{@link Reader}
+ * <li>{@link CharSequence}
+ * <li>{@link InputStream} containing UTF-8 encoded text
(or charset defined by
+ * {@link
org.apache.juneau.parser.ReaderParser.Builder#streamCharset(Charset)} property
value).
+ * <li><code><jk>byte</jk>[]</code> containing UTF-8
encoded text (or charset defined by
+ * {@link
org.apache.juneau.parser.ReaderParser.Builder#streamCharset(Charset)} property
value).
+ * <li>{@link File} containing system encoded text (or
charset defined by
+ * {@link
org.apache.juneau.parser.ReaderParser.Builder#fileCharset(Charset)} property
value).
+ * </ul>
+ * @param type The object type to create.
+ * @return The parsed object.
+ * @throws ParseException Malformed input encountered.
+ * @throws IOException Thrown by underlying stream.
+ */
+ public static <T> T from(Object input, Class<T> type) throws
ParseException, IOException {
+ return DEFAULT.read(input, type);
+ }
+
+ /**
+ * Parses a JSON input string to the specified Java type.
+ *
+ * <p>
+ * A shortcut for calling <c><jsf>DEFAULT</jsf>.read(<jv>input</jv>,
<jv>type</jv>, <jv>args</jv>)</c>.
+ *
+ * @param <T> The class type of the object to create.
+ * @param input The input.
+ * @param type
+ * The object type to create.
+ * <br>Can be any of the following: {@link ClassMeta}, {@link
Class}, {@link ParameterizedType}, {@link GenericArrayType}
+ * @param args
+ * The type arguments of the class if it's a collection or map.
+ * <br>Can be any of the following: {@link ClassMeta}, {@link
Class}, {@link ParameterizedType}, {@link GenericArrayType}
+ * <br>Ignored if the main type is not a map or collection.
+ * @return The parsed object.
+ * @throws ParseException Malformed input encountered.
+ * @see BeanSession#getClassMeta(Type,Type...) for argument syntax for
maps and collections.
+ */
+ public static <T> T from(String input, Type type, Type...args) throws
ParseException {
+ return DEFAULT.read(input, type, args);
+ }
+
+ /**
+ * Parses a JSON input object to the specified Java type.
+ *
+ * <p>
+ * A shortcut for calling <c><jsf>DEFAULT</jsf>.read(<jv>input</jv>,
<jv>type</jv>, <jv>args</jv>)</c>.
+ *
+ * @param <T> The class type of the object to create.
+ * @param input
+ * The input.
+ * <br>Can be any of the following types:
+ * <ul>
+ * <li><jk>null</jk>
+ * <li>{@link Reader}
+ * <li>{@link CharSequence}
+ * <li>{@link InputStream} containing UTF-8 encoded text
(or charset defined by
+ * {@link
org.apache.juneau.parser.ReaderParser.Builder#streamCharset(Charset)} property
value).
+ * <li><code><jk>byte</jk>[]</code> containing UTF-8
encoded text (or charset defined by
+ * {@link
org.apache.juneau.parser.ReaderParser.Builder#streamCharset(Charset)} property
value).
+ * <li>{@link File} containing system encoded text (or
charset defined by
+ * {@link
org.apache.juneau.parser.ReaderParser.Builder#fileCharset(Charset)} property
value).
+ * </ul>
+ * @param type
+ * The object type to create.
+ * <br>Can be any of the following: {@link ClassMeta}, {@link
Class}, {@link ParameterizedType}, {@link GenericArrayType}
+ * @param args
+ * The type arguments of the class if it's a collection or map.
+ * <br>Can be any of the following: {@link ClassMeta}, {@link
Class}, {@link ParameterizedType}, {@link GenericArrayType}
+ * <br>Ignored if the main type is not a map or collection.
+ * @return The parsed object.
+ * @throws ParseException Malformed input encountered.
+ * @throws IOException Thrown by underlying stream.
+ * @see BeanSession#getClassMeta(Type,Type...) for argument syntax for
maps and collections.
+ */
+ public static <T> T from(Object input, Type type, Type...args) throws
ParseException, IOException {
+ return DEFAULT.read(input, type, args);
+ }
+
+ /**
+ * Serializes a Java object to a JSON string.
+ *
+ * <p>
+ * A shortcut for calling
<c><jsf>DEFAULT</jsf>.write(<jv>object</jv>)</c>.
+ *
+ * @param object The object to serialize.
+ * @return
+ * The serialized object.
+ * @throws SerializeException If a problem occurred trying to convert
the output.
+ */
+ public static String to(Object object) throws SerializeException {
+ return DEFAULT.write(object);
+ }
+
+ /**
+ * Serializes a Java object to a JSON output.
+ *
+ * <p>
+ * A shortcut for calling
<c><jsf>DEFAULT</jsf>.write(<jv>output</jv>)</c>.
+ *
+ * @param object The object to serialize.
+ * @param output
+ * The output object.
+ * <br>Can be any of the following types:
+ * <ul>
+ * <li>{@link Writer}
+ * <li>{@link OutputStream} - Output will be written as
UTF-8 encoded stream.
+ * <li>{@link File} - Output will be written as
system-default encoded stream.
+ * <li>{@link StringBuilder} - Output will be written to
the specified string builder.
+ * </ul>
+ * @throws SerializeException If a problem occurred trying to convert
the output.
+ * @throws IOException Thrown by underlying stream.
+ */
+ public static void to(Object object, Object output) throws
SerializeException, IOException {
+ DEFAULT.write(object, output);
+ }
}
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/marshall/Marshall.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/marshall/Marshall.java
index 6c890b6f8..14e28108c 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/marshall/Marshall.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/marshall/Marshall.java
@@ -89,15 +89,15 @@ public abstract class Marshall {
/**
* Serializes a POJO directly to either a <c>String</c> or
<code><jk>byte</jk>[]</code> depending on the serializer type.
*
- * @param o The object to serialize.
+ * @param object The object to serialize.
* @return
* The serialized object.
* <br>Character-based serializers will return a <c>String</c>
* <br>Stream-based serializers will return a
<code><jk>byte</jk>[]</code>
* @throws SerializeException If a problem occurred trying to convert
the output.
*/
- public Object write(Object o) throws SerializeException {
- return s.serialize(o);
+ public Object write(Object object) throws SerializeException {
+ return s.serialize(object);
}
/**
@@ -106,7 +106,7 @@ public abstract class Marshall {
* <p>
* Equivalent to calling <c>serializer.createSession().serialize(o,
output);</c>
*
- * @param o The object to serialize.
+ * @param object The object to serialize.
* @param output
* The output object.
* <br>Character-based serializers can handle the following output
class types:
@@ -124,8 +124,8 @@ public abstract class Marshall {
* @throws SerializeException If a problem occurred trying to convert
the output.
* @throws IOException Thrown by underlying stream.
*/
- public final void write(Object o, Object output) throws
SerializeException, IOException {
- s.serialize(o, output);
+ public final void write(Object object, Object output) throws
SerializeException, IOException {
+ s.serialize(object, output);
}
/**
@@ -136,12 +136,12 @@ public abstract class Marshall {
* <br>For stream-based serializers, this converts the returned byte
array to a string based on
* the {@link
org.apache.juneau.serializer.OutputStreamSerializer.Builder#binaryFormat(BinaryFormat)}
setting.
*
- * @param o The object to serialize.
+ * @param object The object to serialize.
* @return The output serialized to a string.
*/
- public final String toString(Object o) {
+ public final String toString(Object object) {
try {
- return s.serializeToString(o);
+ return s.serializeToString(object);
} catch (Exception e) {
throw runtimeException(e);
}
@@ -151,11 +151,11 @@ public abstract class Marshall {
/**
* Convenience method for calling <c>System.out.println(...)</c> on the
specified object after calling {@link #toString(Object)}.
*
- * @param o The object to serialize and then send to the console.
+ * @param object The object to serialize and then send to the console.
* @return This object.
*/
- public final Marshall println(Object o) {
- System.out.println(toString(o));
+ public final Marshall println(Object object) {
+ System.out.println(toString(object));
return this;
}
@@ -308,47 +308,6 @@ public abstract class Marshall {
return p.parse(input, type, args);
}
- /**
- * Same as {@link #read(Object,Type,Type...)} but reads from a string
and thus doesn't throw an <c>IOException</c>.
- *
- * @param <T> The class type of the object to create.
- * @param input
- * The input.
- * <br>Character-based parsers can handle the following input
class types:
- * <ul>
- * <li><jk>null</jk>
- * <li>{@link Reader}
- * <li>{@link CharSequence}
- * <li>{@link InputStream} containing UTF-8 encoded text
(or charset defined by
- * {@link
org.apache.juneau.parser.ReaderParser.Builder#streamCharset(Charset)} property
value).
- * <li><code><jk>byte</jk>[]</code> containing UTF-8
encoded text (or charset defined by
- * {@link
org.apache.juneau.parser.ReaderParser.Builder#streamCharset(Charset)} property
value).
- * <li>{@link File} containing system encoded text (or
charset defined by
- * {@link
org.apache.juneau.parser.ReaderParser.Builder#fileCharset(Charset)} property
value).
- * </ul>
- * <br>Stream-based parsers can handle the following input class
types:
- * <ul>
- * <li><jk>null</jk>
- * <li>{@link InputStream}
- * <li><code><jk>byte</jk>[]</code>
- * <li>{@link File}
- * <li>{@link CharSequence} containing encoded bytes
according to the {@link
org.apache.juneau.parser.InputStreamParser.Builder#binaryFormat(BinaryFormat)}
setting.
- * </ul>
- * @param type
- * The object type to create.
- * <br>Can be any of the following: {@link ClassMeta}, {@link
Class}, {@link ParameterizedType}, {@link GenericArrayType}
- * @param args
- * The type arguments of the class if it's a collection or map.
- * <br>Can be any of the following: {@link ClassMeta}, {@link
Class}, {@link ParameterizedType}, {@link GenericArrayType}
- * <br>Ignored if the main type is not a map or collection.
- * @return The parsed object.
- * @throws ParseException Malformed input encountered.
- * @see BeanSession#getClassMeta(Type,Type...) for argument syntax for
maps and collections.
- */
- public final <T> T read(String input, Type type, Type...args) throws
ParseException {
- return p.parse(input, type, args);
- }
-
/**
* Same as {@link #read(Object, Type, Type...)} except optimized for a
non-parameterized class.
*
@@ -378,7 +337,26 @@ public abstract class Marshall {
* @param <T> The class type of the object being created.
* @param input
* The input.
- * See {@link #read(Object, Type, Type...)} for details.
+ * <br>Character-based parsers can handle the following input
class types:
+ * <ul>
+ * <li><jk>null</jk>
+ * <li>{@link Reader}
+ * <li>{@link CharSequence}
+ * <li>{@link InputStream} containing UTF-8 encoded text
(or charset defined by
+ * {@link
org.apache.juneau.parser.ReaderParser.Builder#streamCharset(Charset)} property
value).
+ * <li><code><jk>byte</jk>[]</code> containing UTF-8
encoded text (or charset defined by
+ * {@link
org.apache.juneau.parser.ReaderParser.Builder#streamCharset(Charset)} property
value).
+ * <li>{@link File} containing system encoded text (or
charset defined by
+ * {@link
org.apache.juneau.parser.ReaderParser.Builder#fileCharset(Charset)} property
value).
+ * </ul>
+ * <br>Stream-based parsers can handle the following input class
types:
+ * <ul>
+ * <li><jk>null</jk>
+ * <li>{@link InputStream}
+ * <li><code><jk>byte</jk>[]</code>
+ * <li>{@link File}
+ * <li>{@link CharSequence} containing encoded bytes
according to the {@link
org.apache.juneau.parser.InputStreamParser.Builder#binaryFormat(BinaryFormat)}
setting.
+ * </ul>
* @param type The object type to create.
* @return The parsed object.
* @throws ParseException Malformed input encountered.
@@ -387,42 +365,4 @@ public abstract class Marshall {
public final <T> T read(Object input, Class<T> type) throws
ParseException, IOException {
return p.parse(input, type);
}
-
- /**
- * Same as {@link #read(Object,Class)} but reads from a string and thus
doesn't throw an <c>IOException</c>.
- *
- * <p>
- * This is the preferred parse method for simple types since you don't
need to cast the results.
- *
- * <h5 class='section'>Examples:</h5>
- * <p class='bjava'>
- * Marshall <jv>marshall</jv> = Json.<jsf>DEFAULT</jsf>;
- *
- * <jc>// Parse into a string.</jc>
- * String <jv>string</jv> = <jv>marshall</jv>.read(<jv>json</jv>,
String.<jk>class</jk>);
- *
- * <jc>// Parse into a bean.</jc>
- * MyBean <jv>bean</jv> = <jv>marshall</jv>.read(<jv>json</jv>,
MyBean.<jk>class</jk>);
- *
- * <jc>// Parse into a bean array.</jc>
- * MyBean[] <jv>beanArray</jv> =
<jv>marshall</jv>.read(<jv>json</jv>, MyBean[].<jk>class</jk>);
- *
- * <jc>// Parse into a linked-list of objects.</jc>
- * List <jv>list</jv> = <jv>marshall</jv>.read(<jv>json</jv>,
LinkedList.<jk>class</jk>);
- *
- * <jc>// Parse into a map of object keys/values.</jc>
- * Map <jv>map</jv> = <jv>marshall</jv>.read(<jv>json</jv>,
TreeMap.<jk>class</jk>);
- * </p>
- *
- * @param <T> The class type of the object being created.
- * @param input
- * The input.
- * See {@link #read(Object, Type, Type...)} for details.
- * @param type The object type to create.
- * @return The parsed object.
- * @throws ParseException Malformed input encountered.
- */
- public final <T> T read(String input, Class<T> type) throws
ParseException {
- return p.parse(input, type);
- }
}
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/marshall/MsgPack.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/marshall/MsgPack.java
index 747464558..183ed3404 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/marshall/MsgPack.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/marshall/MsgPack.java
@@ -12,7 +12,13 @@
//
***************************************************************************************************************************
package org.apache.juneau.marshall;
+import java.io.*;
+import java.lang.reflect.*;
+
+import org.apache.juneau.*;
import org.apache.juneau.msgpack.*;
+import org.apache.juneau.parser.*;
+import org.apache.juneau.serializer.*;
/**
* A pairing of a {@link MsgPackSerializer} and {@link MsgPackParser} into a
single class with convenience read/write methods.
@@ -68,4 +74,138 @@ public class MsgPack extends StreamMarshall {
public MsgPack() {
this(MsgPackSerializer.DEFAULT, MsgPackParser.DEFAULT);
}
+
+ /**
+ * Parses a JSON input string to the specified type.
+ *
+ * <p>
+ * A shortcut for calling <c><jsf>DEFAULT</jsf>.read(<jv>input</jv>,
<jv>type</jv>)</c>.
+ *
+ * @param <T> The class type of the object being created.
+ * @param input The input.
+ * @param type The object type to create.
+ * @return The parsed object.
+ * @throws ParseException Malformed input encountered.
+ */
+ public static <T> T from(byte[] input, Class<T> type) throws
ParseException {
+ return DEFAULT.read(input, type);
+ }
+
+ /**
+ * Parses a JSON input object to the specified Java type.
+ *
+ * <p>
+ * A shortcut for calling <c><jsf>DEFAULT</jsf>.read(<jv>input</jv>,
<jv>type</jv>)</c>.
+ *
+ * @param <T> The class type of the object being created.
+ * @param input
+ * The input.
+ * <br>Can be any of the following types:
+ * <ul>
+ * <li><jk>null</jk>
+ * <li>{@link InputStream}
+ * <li><code><jk>byte</jk>[]</code>
+ * <li>{@link File}
+ * <li>{@link CharSequence} containing encoded bytes
according to the {@link
org.apache.juneau.parser.InputStreamParser.Builder#binaryFormat(BinaryFormat)}
setting.
+ * </ul>
+ * @param type The object type to create.
+ * @return The parsed object.
+ * @throws ParseException Malformed input encountered.
+ * @throws IOException Thrown by underlying stream.
+ */
+ public static <T> T from(Object input, Class<T> type) throws
ParseException, IOException {
+ return DEFAULT.read(input, type);
+ }
+
+ /**
+ * Parses a JSON input string to the specified Java type.
+ *
+ * <p>
+ * A shortcut for calling <c><jsf>DEFAULT</jsf>.read(<jv>input</jv>,
<jv>type</jv>, <jv>args</jv>)</c>.
+ *
+ * @param <T> The class type of the object to create.
+ * @param input The input.
+ * @param type
+ * The object type to create.
+ * <br>Can be any of the following: {@link ClassMeta}, {@link
Class}, {@link ParameterizedType}, {@link GenericArrayType}
+ * @param args
+ * The type arguments of the class if it's a collection or map.
+ * <br>Can be any of the following: {@link ClassMeta}, {@link
Class}, {@link ParameterizedType}, {@link GenericArrayType}
+ * <br>Ignored if the main type is not a map or collection.
+ * @return The parsed object.
+ * @throws ParseException Malformed input encountered.
+ * @see BeanSession#getClassMeta(Type,Type...) for argument syntax for
maps and collections.
+ */
+ public static <T> T from(byte[] input, Type type, Type...args) throws
ParseException {
+ return DEFAULT.read(input, type, args);
+ }
+
+ /**
+ * Parses a JSON input object to the specified Java type.
+ *
+ * <p>
+ * A shortcut for calling <c><jsf>DEFAULT</jsf>.read(<jv>input</jv>,
<jv>type</jv>, <jv>args</jv>)</c>.
+ *
+ * @param <T> The class type of the object to create.
+ * @param input
+ * The input.
+ * <br>Can be any of the following types:
+ * <ul>
+ * <li><jk>null</jk>
+ * <li>{@link InputStream}
+ * <li><code><jk>byte</jk>[]</code>
+ * <li>{@link File}
+ * <li>{@link CharSequence} containing encoded bytes
according to the {@link
org.apache.juneau.parser.InputStreamParser.Builder#binaryFormat(BinaryFormat)}
setting.
+ * </ul>
+ * @param type
+ * The object type to create.
+ * <br>Can be any of the following: {@link ClassMeta}, {@link
Class}, {@link ParameterizedType}, {@link GenericArrayType}
+ * @param args
+ * The type arguments of the class if it's a collection or map.
+ * <br>Can be any of the following: {@link ClassMeta}, {@link
Class}, {@link ParameterizedType}, {@link GenericArrayType}
+ * <br>Ignored if the main type is not a map or collection.
+ * @return The parsed object.
+ * @throws ParseException Malformed input encountered.
+ * @throws IOException Thrown by underlying stream.
+ * @see BeanSession#getClassMeta(Type,Type...) for argument syntax for
maps and collections.
+ */
+ public static <T> T from(Object input, Type type, Type...args) throws
ParseException, IOException {
+ return DEFAULT.read(input, type, args);
+ }
+
+ /**
+ * Serializes a Java object to a JSON string.
+ *
+ * <p>
+ * A shortcut for calling
<c><jsf>DEFAULT</jsf>.write(<jv>object</jv>)</c>.
+ *
+ * @param object The object to serialize.
+ * @return
+ * The serialized object.
+ * @throws SerializeException If a problem occurred trying to convert
the output.
+ */
+ public static byte[] to(Object object) throws SerializeException {
+ return DEFAULT.write(object);
+ }
+
+ /**
+ * Serializes a Java object to an output.
+ *
+ * <p>
+ * A shortcut for calling
<c><jsf>DEFAULT</jsf>.write(<jv>output</jv>)</c>.
+ *
+ * @param object The object to serialize.
+ * @param output
+ * The output object.
+ * <br>Can be any of the following types:
+ * <ul>
+ * <li>{@link OutputStream}
+ * <li>{@link File}
+ * </ul>
+ * @throws SerializeException If a problem occurred trying to convert
the output.
+ * @throws IOException Thrown by underlying stream.
+ */
+ public static void to(Object object, Object output) throws
SerializeException, IOException {
+ DEFAULT.write(object, output);
+ }
}
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/marshall/OpenApi.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/marshall/OpenApi.java
index abcb3bad3..9edb03cf7 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/marshall/OpenApi.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/marshall/OpenApi.java
@@ -12,7 +12,14 @@
//
***************************************************************************************************************************
package org.apache.juneau.marshall;
+import java.io.*;
+import java.lang.reflect.*;
+import java.nio.charset.*;
+
+import org.apache.juneau.*;
import org.apache.juneau.oapi.*;
+import org.apache.juneau.parser.*;
+import org.apache.juneau.serializer.*;
/**
* A pairing of a {@link OpenApiSerializer} and {@link OpenApiParser} into a
single class with convenience read/write methods.
@@ -68,4 +75,148 @@ public class OpenApi extends CharMarshall {
public OpenApi() {
this(OpenApiSerializer.DEFAULT, OpenApiParser.DEFAULT);
}
+
+ /**
+ * Parses an OpenApi input string to the specified type.
+ *
+ * <p>
+ * A shortcut for calling <c><jsf>DEFAULT</jsf>.read(<jv>input</jv>,
<jv>type</jv>)</c>.
+ *
+ * @param <T> The class type of the object being created.
+ * @param input The input.
+ * @param type The object type to create.
+ * @return The parsed object.
+ * @throws ParseException Malformed input encountered.
+ */
+ public static <T> T from(String input, Class<T> type) throws
ParseException {
+ return DEFAULT.read(input, type);
+ }
+
+ /**
+ * Parses an OpenApi input object to the specified Java type.
+ *
+ * <p>
+ * A shortcut for calling <c><jsf>DEFAULT</jsf>.read(<jv>input</jv>,
<jv>type</jv>)</c>.
+ *
+ * @param <T> The class type of the object being created.
+ * @param input
+ * The input.
+ * <br>Can be any of the following types:
+ * <ul>
+ * <li><jk>null</jk>
+ * <li>{@link Reader}
+ * <li>{@link CharSequence}
+ * <li>{@link InputStream} containing UTF-8 encoded text
(or charset defined by
+ * {@link
org.apache.juneau.parser.ReaderParser.Builder#streamCharset(Charset)} property
value).
+ * <li><code><jk>byte</jk>[]</code> containing UTF-8
encoded text (or charset defined by
+ * {@link
org.apache.juneau.parser.ReaderParser.Builder#streamCharset(Charset)} property
value).
+ * <li>{@link File} containing system encoded text (or
charset defined by
+ * {@link
org.apache.juneau.parser.ReaderParser.Builder#fileCharset(Charset)} property
value).
+ * </ul>
+ * @param type The object type to create.
+ * @return The parsed object.
+ * @throws ParseException Malformed input encountered.
+ * @throws IOException Thrown by underlying stream.
+ */
+ public static <T> T from(Object input, Class<T> type) throws
ParseException, IOException {
+ return DEFAULT.read(input, type);
+ }
+
+ /**
+ * Parses an OpenApi input string to the specified Java type.
+ *
+ * <p>
+ * A shortcut for calling <c><jsf>DEFAULT</jsf>.read(<jv>input</jv>,
<jv>type</jv>, <jv>args</jv>)</c>.
+ *
+ * @param <T> The class type of the object to create.
+ * @param input The input.
+ * @param type
+ * The object type to create.
+ * <br>Can be any of the following: {@link ClassMeta}, {@link
Class}, {@link ParameterizedType}, {@link GenericArrayType}
+ * @param args
+ * The type arguments of the class if it's a collection or map.
+ * <br>Can be any of the following: {@link ClassMeta}, {@link
Class}, {@link ParameterizedType}, {@link GenericArrayType}
+ * <br>Ignored if the main type is not a map or collection.
+ * @return The parsed object.
+ * @throws ParseException Malformed input encountered.
+ * @see BeanSession#getClassMeta(Type,Type...) for argument syntax for
maps and collections.
+ */
+ public static <T> T from(String input, Type type, Type...args) throws
ParseException {
+ return DEFAULT.read(input, type, args);
+ }
+
+ /**
+ * Parses an OpenApi input object to the specified Java type.
+ *
+ * <p>
+ * A shortcut for calling <c><jsf>DEFAULT</jsf>.read(<jv>input</jv>,
<jv>type</jv>, <jv>args</jv>)</c>.
+ *
+ * @param <T> The class type of the object to create.
+ * @param input
+ * The input.
+ * <br>Can be any of the following types:
+ * <ul>
+ * <li><jk>null</jk>
+ * <li>{@link Reader}
+ * <li>{@link CharSequence}
+ * <li>{@link InputStream} containing UTF-8 encoded text
(or charset defined by
+ * {@link
org.apache.juneau.parser.ReaderParser.Builder#streamCharset(Charset)} property
value).
+ * <li><code><jk>byte</jk>[]</code> containing UTF-8
encoded text (or charset defined by
+ * {@link
org.apache.juneau.parser.ReaderParser.Builder#streamCharset(Charset)} property
value).
+ * <li>{@link File} containing system encoded text (or
charset defined by
+ * {@link
org.apache.juneau.parser.ReaderParser.Builder#fileCharset(Charset)} property
value).
+ * </ul>
+ * @param type
+ * The object type to create.
+ * <br>Can be any of the following: {@link ClassMeta}, {@link
Class}, {@link ParameterizedType}, {@link GenericArrayType}
+ * @param args
+ * The type arguments of the class if it's a collection or map.
+ * <br>Can be any of the following: {@link ClassMeta}, {@link
Class}, {@link ParameterizedType}, {@link GenericArrayType}
+ * <br>Ignored if the main type is not a map or collection.
+ * @return The parsed object.
+ * @throws ParseException Malformed input encountered.
+ * @throws IOException Thrown by underlying stream.
+ * @see BeanSession#getClassMeta(Type,Type...) for argument syntax for
maps and collections.
+ */
+ public static <T> T from(Object input, Type type, Type...args) throws
ParseException, IOException {
+ return DEFAULT.read(input, type, args);
+ }
+
+ /**
+ * Serializes a Java object to an OpenApi string.
+ *
+ * <p>
+ * A shortcut for calling
<c><jsf>DEFAULT</jsf>.write(<jv>object</jv>)</c>.
+ *
+ * @param object The object to serialize.
+ * @return
+ * The serialized object.
+ * @throws SerializeException If a problem occurred trying to convert
the output.
+ */
+ public static String to(Object object) throws SerializeException {
+ return DEFAULT.write(object);
+ }
+
+ /**
+ * Serializes a Java object to an OpenApi output.
+ *
+ * <p>
+ * A shortcut for calling
<c><jsf>DEFAULT</jsf>.write(<jv>output</jv>)</c>.
+ *
+ * @param object The object to serialize.
+ * @param output
+ * The output object.
+ * <br>Can be any of the following types:
+ * <ul>
+ * <li>{@link Writer}
+ * <li>{@link OutputStream} - Output will be written as
UTF-8 encoded stream.
+ * <li>{@link File} - Output will be written as
system-default encoded stream.
+ * <li>{@link StringBuilder} - Output will be written to
the specified string builder.
+ * </ul>
+ * @throws SerializeException If a problem occurred trying to convert
the output.
+ * @throws IOException Thrown by underlying stream.
+ */
+ public static void to(Object object, Object output) throws
SerializeException, IOException {
+ DEFAULT.write(object, output);
+ }
}
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/marshall/PlainText.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/marshall/PlainText.java
index 998fa196a..b568c050a 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/marshall/PlainText.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/marshall/PlainText.java
@@ -12,7 +12,14 @@
//
***************************************************************************************************************************
package org.apache.juneau.marshall;
+import java.io.*;
+import java.lang.reflect.*;
+import java.nio.charset.*;
+
+import org.apache.juneau.*;
+import org.apache.juneau.parser.*;
import org.apache.juneau.plaintext.*;
+import org.apache.juneau.serializer.*;
/**
* A pairing of a {@link PlainTextSerializer} and {@link PlainTextParser} into
a single class with convenience read/write methods.
@@ -68,4 +75,148 @@ public class PlainText extends CharMarshall {
public PlainText() {
this(PlainTextSerializer.DEFAULT, PlainTextParser.DEFAULT);
}
+
+ /**
+ * Parses a Plain Text input string to the specified type.
+ *
+ * <p>
+ * A shortcut for calling <c><jsf>DEFAULT</jsf>.read(<jv>input</jv>,
<jv>type</jv>)</c>.
+ *
+ * @param <T> The class type of the object being created.
+ * @param input The input.
+ * @param type The object type to create.
+ * @return The parsed object.
+ * @throws ParseException Malformed input encountered.
+ */
+ public static <T> T from(String input, Class<T> type) throws
ParseException {
+ return DEFAULT.read(input, type);
+ }
+
+ /**
+ * Parses a Plain Text input object to the specified Java type.
+ *
+ * <p>
+ * A shortcut for calling <c><jsf>DEFAULT</jsf>.read(<jv>input</jv>,
<jv>type</jv>)</c>.
+ *
+ * @param <T> The class type of the object being created.
+ * @param input
+ * The input.
+ * <br>Can be any of the following types:
+ * <ul>
+ * <li><jk>null</jk>
+ * <li>{@link Reader}
+ * <li>{@link CharSequence}
+ * <li>{@link InputStream} containing UTF-8 encoded text
(or charset defined by
+ * {@link
org.apache.juneau.parser.ReaderParser.Builder#streamCharset(Charset)} property
value).
+ * <li><code><jk>byte</jk>[]</code> containing UTF-8
encoded text (or charset defined by
+ * {@link
org.apache.juneau.parser.ReaderParser.Builder#streamCharset(Charset)} property
value).
+ * <li>{@link File} containing system encoded text (or
charset defined by
+ * {@link
org.apache.juneau.parser.ReaderParser.Builder#fileCharset(Charset)} property
value).
+ * </ul>
+ * @param type The object type to create.
+ * @return The parsed object.
+ * @throws ParseException Malformed input encountered.
+ * @throws IOException Thrown by underlying stream.
+ */
+ public static <T> T from(Object input, Class<T> type) throws
ParseException, IOException {
+ return DEFAULT.read(input, type);
+ }
+
+ /**
+ * Parses a Plain Text input string to the specified Java type.
+ *
+ * <p>
+ * A shortcut for calling <c><jsf>DEFAULT</jsf>.read(<jv>input</jv>,
<jv>type</jv>, <jv>args</jv>)</c>.
+ *
+ * @param <T> The class type of the object to create.
+ * @param input The input.
+ * @param type
+ * The object type to create.
+ * <br>Can be any of the following: {@link ClassMeta}, {@link
Class}, {@link ParameterizedType}, {@link GenericArrayType}
+ * @param args
+ * The type arguments of the class if it's a collection or map.
+ * <br>Can be any of the following: {@link ClassMeta}, {@link
Class}, {@link ParameterizedType}, {@link GenericArrayType}
+ * <br>Ignored if the main type is not a map or collection.
+ * @return The parsed object.
+ * @throws ParseException Malformed input encountered.
+ * @see BeanSession#getClassMeta(Type,Type...) for argument syntax for
maps and collections.
+ */
+ public static <T> T from(String input, Type type, Type...args) throws
ParseException {
+ return DEFAULT.read(input, type, args);
+ }
+
+ /**
+ * Parses a Plain Text input object to the specified Java type.
+ *
+ * <p>
+ * A shortcut for calling <c><jsf>DEFAULT</jsf>.read(<jv>input</jv>,
<jv>type</jv>, <jv>args</jv>)</c>.
+ *
+ * @param <T> The class type of the object to create.
+ * @param input
+ * The input.
+ * <br>Can be any of the following types:
+ * <ul>
+ * <li><jk>null</jk>
+ * <li>{@link Reader}
+ * <li>{@link CharSequence}
+ * <li>{@link InputStream} containing UTF-8 encoded text
(or charset defined by
+ * {@link
org.apache.juneau.parser.ReaderParser.Builder#streamCharset(Charset)} property
value).
+ * <li><code><jk>byte</jk>[]</code> containing UTF-8
encoded text (or charset defined by
+ * {@link
org.apache.juneau.parser.ReaderParser.Builder#streamCharset(Charset)} property
value).
+ * <li>{@link File} containing system encoded text (or
charset defined by
+ * {@link
org.apache.juneau.parser.ReaderParser.Builder#fileCharset(Charset)} property
value).
+ * </ul>
+ * @param type
+ * The object type to create.
+ * <br>Can be any of the following: {@link ClassMeta}, {@link
Class}, {@link ParameterizedType}, {@link GenericArrayType}
+ * @param args
+ * The type arguments of the class if it's a collection or map.
+ * <br>Can be any of the following: {@link ClassMeta}, {@link
Class}, {@link ParameterizedType}, {@link GenericArrayType}
+ * <br>Ignored if the main type is not a map or collection.
+ * @return The parsed object.
+ * @throws ParseException Malformed input encountered.
+ * @throws IOException Thrown by underlying stream.
+ * @see BeanSession#getClassMeta(Type,Type...) for argument syntax for
maps and collections.
+ */
+ public static <T> T from(Object input, Type type, Type...args) throws
ParseException, IOException {
+ return DEFAULT.read(input, type, args);
+ }
+
+ /**
+ * Serializes a Java object to a Plain Text string.
+ *
+ * <p>
+ * A shortcut for calling
<c><jsf>DEFAULT</jsf>.write(<jv>object</jv>)</c>.
+ *
+ * @param object The object to serialize.
+ * @return
+ * The serialized object.
+ * @throws SerializeException If a problem occurred trying to convert
the output.
+ */
+ public static String to(Object object) throws SerializeException {
+ return DEFAULT.write(object);
+ }
+
+ /**
+ * Serializes a Java object to a Plain Text output.
+ *
+ * <p>
+ * A shortcut for calling
<c><jsf>DEFAULT</jsf>.write(<jv>output</jv>)</c>.
+ *
+ * @param object The object to serialize.
+ * @param output
+ * The output object.
+ * <br>Can be any of the following types:
+ * <ul>
+ * <li>{@link Writer}
+ * <li>{@link OutputStream} - Output will be written as
UTF-8 encoded stream.
+ * <li>{@link File} - Output will be written as
system-default encoded stream.
+ * <li>{@link StringBuilder} - Output will be written to
the specified string builder.
+ * </ul>
+ * @throws SerializeException If a problem occurred trying to convert
the output.
+ * @throws IOException Thrown by underlying stream.
+ */
+ public static void to(Object object, Object output) throws
SerializeException, IOException {
+ DEFAULT.write(object, output);
+ }
}
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/marshall/SimpleJson.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/marshall/SimpleJson.java
index b2e5f7704..ebcb576d5 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/marshall/SimpleJson.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/marshall/SimpleJson.java
@@ -12,7 +12,14 @@
//
***************************************************************************************************************************
package org.apache.juneau.marshall;
+import java.io.*;
+import java.lang.reflect.*;
+import java.nio.charset.*;
+
+import org.apache.juneau.*;
import org.apache.juneau.json.*;
+import org.apache.juneau.parser.*;
+import org.apache.juneau.serializer.*;
/**
* A pairing of a {@link SimpleJsonSerializer} and {@link JsonParser} into a
single class with convenience read/write methods.
@@ -73,4 +80,148 @@ public class SimpleJson extends Json {
public SimpleJson() {
this(SimpleJsonSerializer.DEFAULT, SimpleJsonParser.DEFAULT);
}
+
+ /**
+ * Parses a Simple JSON input string to the specified type.
+ *
+ * <p>
+ * A shortcut for calling <c><jsf>DEFAULT</jsf>.read(<jv>input</jv>,
<jv>type</jv>)</c>.
+ *
+ * @param <T> The class type of the object being created.
+ * @param input The input.
+ * @param type The object type to create.
+ * @return The parsed object.
+ * @throws ParseException Malformed input encountered.
+ */
+ public static <T> T from(String input, Class<T> type) throws
ParseException {
+ return DEFAULT.read(input, type);
+ }
+
+ /**
+ * Parses a Simple JSON input object to the specified Java type.
+ *
+ * <p>
+ * A shortcut for calling <c><jsf>DEFAULT</jsf>.read(<jv>input</jv>,
<jv>type</jv>)</c>.
+ *
+ * @param <T> The class type of the object being created.
+ * @param input
+ * The input.
+ * <br>Can be any of the following types:
+ * <ul>
+ * <li><jk>null</jk>
+ * <li>{@link Reader}
+ * <li>{@link CharSequence}
+ * <li>{@link InputStream} containing UTF-8 encoded text
(or charset defined by
+ * {@link
org.apache.juneau.parser.ReaderParser.Builder#streamCharset(Charset)} property
value).
+ * <li><code><jk>byte</jk>[]</code> containing UTF-8
encoded text (or charset defined by
+ * {@link
org.apache.juneau.parser.ReaderParser.Builder#streamCharset(Charset)} property
value).
+ * <li>{@link File} containing system encoded text (or
charset defined by
+ * {@link
org.apache.juneau.parser.ReaderParser.Builder#fileCharset(Charset)} property
value).
+ * </ul>
+ * @param type The object type to create.
+ * @return The parsed object.
+ * @throws ParseException Malformed input encountered.
+ * @throws IOException Thrown by underlying stream.
+ */
+ public static <T> T from(Object input, Class<T> type) throws
ParseException, IOException {
+ return DEFAULT.read(input, type);
+ }
+
+ /**
+ * Parses a Simple JSON input string to the specified Java type.
+ *
+ * <p>
+ * A shortcut for calling <c><jsf>DEFAULT</jsf>.read(<jv>input</jv>,
<jv>type</jv>, <jv>args</jv>)</c>.
+ *
+ * @param <T> The class type of the object to create.
+ * @param input The input.
+ * @param type
+ * The object type to create.
+ * <br>Can be any of the following: {@link ClassMeta}, {@link
Class}, {@link ParameterizedType}, {@link GenericArrayType}
+ * @param args
+ * The type arguments of the class if it's a collection or map.
+ * <br>Can be any of the following: {@link ClassMeta}, {@link
Class}, {@link ParameterizedType}, {@link GenericArrayType}
+ * <br>Ignored if the main type is not a map or collection.
+ * @return The parsed object.
+ * @throws ParseException Malformed input encountered.
+ * @see BeanSession#getClassMeta(Type,Type...) for argument syntax for
maps and collections.
+ */
+ public static <T> T from(String input, Type type, Type...args) throws
ParseException {
+ return DEFAULT.read(input, type, args);
+ }
+
+ /**
+ * Parses a Simple JSON input object to the specified Java type.
+ *
+ * <p>
+ * A shortcut for calling <c><jsf>DEFAULT</jsf>.read(<jv>input</jv>,
<jv>type</jv>, <jv>args</jv>)</c>.
+ *
+ * @param <T> The class type of the object to create.
+ * @param input
+ * The input.
+ * <br>Can be any of the following types:
+ * <ul>
+ * <li><jk>null</jk>
+ * <li>{@link Reader}
+ * <li>{@link CharSequence}
+ * <li>{@link InputStream} containing UTF-8 encoded text
(or charset defined by
+ * {@link
org.apache.juneau.parser.ReaderParser.Builder#streamCharset(Charset)} property
value).
+ * <li><code><jk>byte</jk>[]</code> containing UTF-8
encoded text (or charset defined by
+ * {@link
org.apache.juneau.parser.ReaderParser.Builder#streamCharset(Charset)} property
value).
+ * <li>{@link File} containing system encoded text (or
charset defined by
+ * {@link
org.apache.juneau.parser.ReaderParser.Builder#fileCharset(Charset)} property
value).
+ * </ul>
+ * @param type
+ * The object type to create.
+ * <br>Can be any of the following: {@link ClassMeta}, {@link
Class}, {@link ParameterizedType}, {@link GenericArrayType}
+ * @param args
+ * The type arguments of the class if it's a collection or map.
+ * <br>Can be any of the following: {@link ClassMeta}, {@link
Class}, {@link ParameterizedType}, {@link GenericArrayType}
+ * <br>Ignored if the main type is not a map or collection.
+ * @return The parsed object.
+ * @throws ParseException Malformed input encountered.
+ * @throws IOException Thrown by underlying stream.
+ * @see BeanSession#getClassMeta(Type,Type...) for argument syntax for
maps and collections.
+ */
+ public static <T> T from(Object input, Type type, Type...args) throws
ParseException, IOException {
+ return DEFAULT.read(input, type, args);
+ }
+
+ /**
+ * Serializes a Java object to a Simple JSON string.
+ *
+ * <p>
+ * A shortcut for calling
<c><jsf>DEFAULT</jsf>.write(<jv>object</jv>)</c>.
+ *
+ * @param object The object to serialize.
+ * @return
+ * The serialized object.
+ * @throws SerializeException If a problem occurred trying to convert
the output.
+ */
+ public static String to(Object object) throws SerializeException {
+ return DEFAULT.write(object);
+ }
+
+ /**
+ * Serializes a Java object to a Simple JSON output.
+ *
+ * <p>
+ * A shortcut for calling
<c><jsf>DEFAULT</jsf>.write(<jv>output</jv>)</c>.
+ *
+ * @param object The object to serialize.
+ * @param output
+ * The output object.
+ * <br>Can be any of the following types:
+ * <ul>
+ * <li>{@link Writer}
+ * <li>{@link OutputStream} - Output will be written as
UTF-8 encoded stream.
+ * <li>{@link File} - Output will be written as
system-default encoded stream.
+ * <li>{@link StringBuilder} - Output will be written to
the specified string builder.
+ * </ul>
+ * @throws SerializeException If a problem occurred trying to convert
the output.
+ * @throws IOException Thrown by underlying stream.
+ */
+ public static void to(Object object, Object output) throws
SerializeException, IOException {
+ DEFAULT.write(object, output);
+ }
}
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/marshall/StreamMarshall.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/marshall/StreamMarshall.java
index 4aa37a80a..bc9aae3eb 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/marshall/StreamMarshall.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/marshall/StreamMarshall.java
@@ -12,6 +12,10 @@
//
***************************************************************************************************************************
package org.apache.juneau.marshall;
+import java.io.*;
+import java.lang.reflect.*;
+
+import org.apache.juneau.*;
import org.apache.juneau.parser.*;
import org.apache.juneau.serializer.*;
@@ -26,6 +30,7 @@ import org.apache.juneau.serializer.*;
public class StreamMarshall extends Marshall {
private final OutputStreamSerializer s;
+ private final InputStreamParser p;
/**
* Constructor.
@@ -40,6 +45,69 @@ public class StreamMarshall extends Marshall {
public StreamMarshall(OutputStreamSerializer s, InputStreamParser p) {
super(s, p);
this.s = s;
+ this.p = p;
+ }
+
+ /**
+ * Same as {@link #read(Object,Class)} but reads from a byte array and
thus doesn't throw an <c>IOException</c>.
+ *
+ * <p>
+ * This is the preferred parse method for simple types since you don't
need to cast the results.
+ *
+ * <h5 class='section'>Examples:</h5>
+ * <p class='bjava'>
+ * Marshall <jv>marshall</jv> = Json.<jsf>DEFAULT</jsf>;
+ *
+ * <jc>// Parse into a string.</jc>
+ * String <jv>string</jv> = <jv>marshall</jv>.read(<jv>json</jv>,
String.<jk>class</jk>);
+ *
+ * <jc>// Parse into a bean.</jc>
+ * MyBean <jv>bean</jv> = <jv>marshall</jv>.read(<jv>json</jv>,
MyBean.<jk>class</jk>);
+ *
+ * <jc>// Parse into a bean array.</jc>
+ * MyBean[] <jv>beanArray</jv> =
<jv>marshall</jv>.read(<jv>json</jv>, MyBean[].<jk>class</jk>);
+ *
+ * <jc>// Parse into a linked-list of objects.</jc>
+ * List <jv>list</jv> = <jv>marshall</jv>.read(<jv>json</jv>,
LinkedList.<jk>class</jk>);
+ *
+ * <jc>// Parse into a map of object keys/values.</jc>
+ * Map <jv>map</jv> = <jv>marshall</jv>.read(<jv>json</jv>,
TreeMap.<jk>class</jk>);
+ * </p>
+ *
+ * @param <T> The class type of the object being created.
+ * @param input The input.
+ * @param type The object type to create.
+ * @return The parsed object.
+ * @throws ParseException Malformed input encountered.
+ */
+ public final <T> T read(byte[] input, Class<T> type) throws
ParseException {
+ try {
+ return p.parse(input, type);
+ } catch (IOException e) {
+ throw new ParseException(e);
+ }
+ }
+
+ /**
+ * Same as {@link #read(Object,Type,Type...)} but reads from a byte
array and thus doesn't throw an <c>IOException</c>.
+ *
+ * @param <T> The class type of the object to create.
+ * @param input The input.
+ * @param type
+ * The object type to create.
+ * <br>Can be any of the following: {@link ClassMeta}, {@link
Class}, {@link ParameterizedType}, {@link GenericArrayType}
+ * @param args
+ * The type arguments of the class if it's a collection or map.
+ * <br>Can be any of the following: {@link ClassMeta}, {@link
Class}, {@link ParameterizedType}, {@link GenericArrayType}
+ * <br>Ignored if the main type is not a map or collection.
+ * @return The parsed object.
+ * @throws ParseException Malformed input encountered.
+ * @see BeanSession#getClassMeta(Type,Type...) for argument syntax for
maps and collections.
+ */
+ public final <T> T read(byte[] input, Type type, Type...args) throws
ParseException {
+ try {
+ return p.parse(input, type, args);
+ } catch (IOException e) { throw new ParseException(e); }
}
/**
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/marshall/Uon.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/marshall/Uon.java
index a18d87a8f..409c3c7cb 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/marshall/Uon.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/marshall/Uon.java
@@ -12,6 +12,13 @@
//
***************************************************************************************************************************
package org.apache.juneau.marshall;
+import java.io.*;
+import java.lang.reflect.*;
+import java.nio.charset.*;
+
+import org.apache.juneau.*;
+import org.apache.juneau.parser.*;
+import org.apache.juneau.serializer.*;
import org.apache.juneau.uon.*;
/**
@@ -68,4 +75,148 @@ public class Uon extends CharMarshall {
public Uon() {
this(UonSerializer.DEFAULT, UonParser.DEFAULT);
}
+
+ /**
+ * Parses a UON input string to the specified type.
+ *
+ * <p>
+ * A shortcut for calling <c><jsf>DEFAULT</jsf>.read(<jv>input</jv>,
<jv>type</jv>)</c>.
+ *
+ * @param <T> The class type of the object being created.
+ * @param input The input.
+ * @param type The object type to create.
+ * @return The parsed object.
+ * @throws ParseException Malformed input encountered.
+ */
+ public static <T> T from(String input, Class<T> type) throws
ParseException {
+ return DEFAULT.read(input, type);
+ }
+
+ /**
+ * Parses a UON input object to the specified Java type.
+ *
+ * <p>
+ * A shortcut for calling <c><jsf>DEFAULT</jsf>.read(<jv>input</jv>,
<jv>type</jv>)</c>.
+ *
+ * @param <T> The class type of the object being created.
+ * @param input
+ * The input.
+ * <br>Can be any of the following types:
+ * <ul>
+ * <li><jk>null</jk>
+ * <li>{@link Reader}
+ * <li>{@link CharSequence}
+ * <li>{@link InputStream} containing UTF-8 encoded text
(or charset defined by
+ * {@link
org.apache.juneau.parser.ReaderParser.Builder#streamCharset(Charset)} property
value).
+ * <li><code><jk>byte</jk>[]</code> containing UTF-8
encoded text (or charset defined by
+ * {@link
org.apache.juneau.parser.ReaderParser.Builder#streamCharset(Charset)} property
value).
+ * <li>{@link File} containing system encoded text (or
charset defined by
+ * {@link
org.apache.juneau.parser.ReaderParser.Builder#fileCharset(Charset)} property
value).
+ * </ul>
+ * @param type The object type to create.
+ * @return The parsed object.
+ * @throws ParseException Malformed input encountered.
+ * @throws IOException Thrown by underlying stream.
+ */
+ public static <T> T from(Object input, Class<T> type) throws
ParseException, IOException {
+ return DEFAULT.read(input, type);
+ }
+
+ /**
+ * Parses a UON input string to the specified Java type.
+ *
+ * <p>
+ * A shortcut for calling <c><jsf>DEFAULT</jsf>.read(<jv>input</jv>,
<jv>type</jv>, <jv>args</jv>)</c>.
+ *
+ * @param <T> The class type of the object to create.
+ * @param input The input.
+ * @param type
+ * The object type to create.
+ * <br>Can be any of the following: {@link ClassMeta}, {@link
Class}, {@link ParameterizedType}, {@link GenericArrayType}
+ * @param args
+ * The type arguments of the class if it's a collection or map.
+ * <br>Can be any of the following: {@link ClassMeta}, {@link
Class}, {@link ParameterizedType}, {@link GenericArrayType}
+ * <br>Ignored if the main type is not a map or collection.
+ * @return The parsed object.
+ * @throws ParseException Malformed input encountered.
+ * @see BeanSession#getClassMeta(Type,Type...) for argument syntax for
maps and collections.
+ */
+ public static <T> T from(String input, Type type, Type...args) throws
ParseException {
+ return DEFAULT.read(input, type, args);
+ }
+
+ /**
+ * Parses a UON input object to the specified Java type.
+ *
+ * <p>
+ * A shortcut for calling <c><jsf>DEFAULT</jsf>.read(<jv>input</jv>,
<jv>type</jv>, <jv>args</jv>)</c>.
+ *
+ * @param <T> The class type of the object to create.
+ * @param input
+ * The input.
+ * <br>Can be any of the following types:
+ * <ul>
+ * <li><jk>null</jk>
+ * <li>{@link Reader}
+ * <li>{@link CharSequence}
+ * <li>{@link InputStream} containing UTF-8 encoded text
(or charset defined by
+ * {@link
org.apache.juneau.parser.ReaderParser.Builder#streamCharset(Charset)} property
value).
+ * <li><code><jk>byte</jk>[]</code> containing UTF-8
encoded text (or charset defined by
+ * {@link
org.apache.juneau.parser.ReaderParser.Builder#streamCharset(Charset)} property
value).
+ * <li>{@link File} containing system encoded text (or
charset defined by
+ * {@link
org.apache.juneau.parser.ReaderParser.Builder#fileCharset(Charset)} property
value).
+ * </ul>
+ * @param type
+ * The object type to create.
+ * <br>Can be any of the following: {@link ClassMeta}, {@link
Class}, {@link ParameterizedType}, {@link GenericArrayType}
+ * @param args
+ * The type arguments of the class if it's a collection or map.
+ * <br>Can be any of the following: {@link ClassMeta}, {@link
Class}, {@link ParameterizedType}, {@link GenericArrayType}
+ * <br>Ignored if the main type is not a map or collection.
+ * @return The parsed object.
+ * @throws ParseException Malformed input encountered.
+ * @throws IOException Thrown by underlying stream.
+ * @see BeanSession#getClassMeta(Type,Type...) for argument syntax for
maps and collections.
+ */
+ public static <T> T from(Object input, Type type, Type...args) throws
ParseException, IOException {
+ return DEFAULT.read(input, type, args);
+ }
+
+ /**
+ * Serializes a Java object to a UON string.
+ *
+ * <p>
+ * A shortcut for calling
<c><jsf>DEFAULT</jsf>.write(<jv>object</jv>)</c>.
+ *
+ * @param object The object to serialize.
+ * @return
+ * The serialized object.
+ * @throws SerializeException If a problem occurred trying to convert
the output.
+ */
+ public static String to(Object object) throws SerializeException {
+ return DEFAULT.write(object);
+ }
+
+ /**
+ * Serializes a Java object to a UON output.
+ *
+ * <p>
+ * A shortcut for calling
<c><jsf>DEFAULT</jsf>.write(<jv>output</jv>)</c>.
+ *
+ * @param object The object to serialize.
+ * @param output
+ * The output object.
+ * <br>Can be any of the following types:
+ * <ul>
+ * <li>{@link Writer}
+ * <li>{@link OutputStream} - Output will be written as
UTF-8 encoded stream.
+ * <li>{@link File} - Output will be written as
system-default encoded stream.
+ * <li>{@link StringBuilder} - Output will be written to
the specified string builder.
+ * </ul>
+ * @throws SerializeException If a problem occurred trying to convert
the output.
+ * @throws IOException Thrown by underlying stream.
+ */
+ public static void to(Object object, Object output) throws
SerializeException, IOException {
+ DEFAULT.write(object, output);
+ }
}
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/marshall/UrlEncoding.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/marshall/UrlEncoding.java
index 188ebce6c..2e51b6165 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/marshall/UrlEncoding.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/marshall/UrlEncoding.java
@@ -12,6 +12,13 @@
//
***************************************************************************************************************************
package org.apache.juneau.marshall;
+import java.io.*;
+import java.lang.reflect.*;
+import java.nio.charset.*;
+
+import org.apache.juneau.*;
+import org.apache.juneau.parser.*;
+import org.apache.juneau.serializer.*;
import org.apache.juneau.urlencoding.*;
/**
@@ -68,4 +75,148 @@ public class UrlEncoding extends CharMarshall {
public UrlEncoding() {
this(UrlEncodingSerializer.DEFAULT, UrlEncodingParser.DEFAULT);
}
+
+ /**
+ * Parses a URL-Encoded input string to the specified type.
+ *
+ * <p>
+ * A shortcut for calling <c><jsf>DEFAULT</jsf>.read(<jv>input</jv>,
<jv>type</jv>)</c>.
+ *
+ * @param <T> The class type of the object being created.
+ * @param input The input.
+ * @param type The object type to create.
+ * @return The parsed object.
+ * @throws ParseException Malformed input encountered.
+ */
+ public static <T> T from(String input, Class<T> type) throws
ParseException {
+ return DEFAULT.read(input, type);
+ }
+
+ /**
+ * Parses a URL-Encoded input object to the specified Java type.
+ *
+ * <p>
+ * A shortcut for calling <c><jsf>DEFAULT</jsf>.read(<jv>input</jv>,
<jv>type</jv>)</c>.
+ *
+ * @param <T> The class type of the object being created.
+ * @param input
+ * The input.
+ * <br>Can be any of the following types:
+ * <ul>
+ * <li><jk>null</jk>
+ * <li>{@link Reader}
+ * <li>{@link CharSequence}
+ * <li>{@link InputStream} containing UTF-8 encoded text
(or charset defined by
+ * {@link
org.apache.juneau.parser.ReaderParser.Builder#streamCharset(Charset)} property
value).
+ * <li><code><jk>byte</jk>[]</code> containing UTF-8
encoded text (or charset defined by
+ * {@link
org.apache.juneau.parser.ReaderParser.Builder#streamCharset(Charset)} property
value).
+ * <li>{@link File} containing system encoded text (or
charset defined by
+ * {@link
org.apache.juneau.parser.ReaderParser.Builder#fileCharset(Charset)} property
value).
+ * </ul>
+ * @param type The object type to create.
+ * @return The parsed object.
+ * @throws ParseException Malformed input encountered.
+ * @throws IOException Thrown by underlying stream.
+ */
+ public static <T> T from(Object input, Class<T> type) throws
ParseException, IOException {
+ return DEFAULT.read(input, type);
+ }
+
+ /**
+ * Parses a URL-Encoded input string to the specified Java type.
+ *
+ * <p>
+ * A shortcut for calling <c><jsf>DEFAULT</jsf>.read(<jv>input</jv>,
<jv>type</jv>, <jv>args</jv>)</c>.
+ *
+ * @param <T> The class type of the object to create.
+ * @param input The input.
+ * @param type
+ * The object type to create.
+ * <br>Can be any of the following: {@link ClassMeta}, {@link
Class}, {@link ParameterizedType}, {@link GenericArrayType}
+ * @param args
+ * The type arguments of the class if it's a collection or map.
+ * <br>Can be any of the following: {@link ClassMeta}, {@link
Class}, {@link ParameterizedType}, {@link GenericArrayType}
+ * <br>Ignored if the main type is not a map or collection.
+ * @return The parsed object.
+ * @throws ParseException Malformed input encountered.
+ * @see BeanSession#getClassMeta(Type,Type...) for argument syntax for
maps and collections.
+ */
+ public static <T> T from(String input, Type type, Type...args) throws
ParseException {
+ return DEFAULT.read(input, type, args);
+ }
+
+ /**
+ * Parses a URL-Encoded input object to the specified Java type.
+ *
+ * <p>
+ * A shortcut for calling <c><jsf>DEFAULT</jsf>.read(<jv>input</jv>,
<jv>type</jv>, <jv>args</jv>)</c>.
+ *
+ * @param <T> The class type of the object to create.
+ * @param input
+ * The input.
+ * <br>Can be any of the following types:
+ * <ul>
+ * <li><jk>null</jk>
+ * <li>{@link Reader}
+ * <li>{@link CharSequence}
+ * <li>{@link InputStream} containing UTF-8 encoded text
(or charset defined by
+ * {@link
org.apache.juneau.parser.ReaderParser.Builder#streamCharset(Charset)} property
value).
+ * <li><code><jk>byte</jk>[]</code> containing UTF-8
encoded text (or charset defined by
+ * {@link
org.apache.juneau.parser.ReaderParser.Builder#streamCharset(Charset)} property
value).
+ * <li>{@link File} containing system encoded text (or
charset defined by
+ * {@link
org.apache.juneau.parser.ReaderParser.Builder#fileCharset(Charset)} property
value).
+ * </ul>
+ * @param type
+ * The object type to create.
+ * <br>Can be any of the following: {@link ClassMeta}, {@link
Class}, {@link ParameterizedType}, {@link GenericArrayType}
+ * @param args
+ * The type arguments of the class if it's a collection or map.
+ * <br>Can be any of the following: {@link ClassMeta}, {@link
Class}, {@link ParameterizedType}, {@link GenericArrayType}
+ * <br>Ignored if the main type is not a map or collection.
+ * @return The parsed object.
+ * @throws ParseException Malformed input encountered.
+ * @throws IOException Thrown by underlying stream.
+ * @see BeanSession#getClassMeta(Type,Type...) for argument syntax for
maps and collections.
+ */
+ public static <T> T from(Object input, Type type, Type...args) throws
ParseException, IOException {
+ return DEFAULT.read(input, type, args);
+ }
+
+ /**
+ * Serializes a Java object to a URL-Encoded string.
+ *
+ * <p>
+ * A shortcut for calling
<c><jsf>DEFAULT</jsf>.write(<jv>object</jv>)</c>.
+ *
+ * @param object The object to serialize.
+ * @return
+ * The serialized object.
+ * @throws SerializeException If a problem occurred trying to convert
the output.
+ */
+ public static String to(Object object) throws SerializeException {
+ return DEFAULT.write(object);
+ }
+
+ /**
+ * Serializes a Java object to a URL-Encoded output.
+ *
+ * <p>
+ * A shortcut for calling
<c><jsf>DEFAULT</jsf>.write(<jv>output</jv>)</c>.
+ *
+ * @param object The object to serialize.
+ * @param output
+ * The output object.
+ * <br>Can be any of the following types:
+ * <ul>
+ * <li>{@link Writer}
+ * <li>{@link OutputStream} - Output will be written as
UTF-8 encoded stream.
+ * <li>{@link File} - Output will be written as
system-default encoded stream.
+ * <li>{@link StringBuilder} - Output will be written to
the specified string builder.
+ * </ul>
+ * @throws SerializeException If a problem occurred trying to convert
the output.
+ * @throws IOException Thrown by underlying stream.
+ */
+ public static void to(Object object, Object output) throws
SerializeException, IOException {
+ DEFAULT.write(object, output);
+ }
}
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/marshall/Xml.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/marshall/Xml.java
index e4418eb0f..26c26a74d 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/marshall/Xml.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/marshall/Xml.java
@@ -12,6 +12,13 @@
//
***************************************************************************************************************************
package org.apache.juneau.marshall;
+import java.io.*;
+import java.lang.reflect.*;
+import java.nio.charset.*;
+
+import org.apache.juneau.*;
+import org.apache.juneau.parser.*;
+import org.apache.juneau.serializer.*;
import org.apache.juneau.xml.*;
/**
@@ -68,4 +75,148 @@ public class Xml extends CharMarshall {
public Xml() {
this(XmlSerializer.DEFAULT, XmlParser.DEFAULT);
}
+
+ /**
+ * Parses an XML input string to the specified type.
+ *
+ * <p>
+ * A shortcut for calling <c><jsf>DEFAULT</jsf>.read(<jv>input</jv>,
<jv>type</jv>)</c>.
+ *
+ * @param <T> The class type of the object being created.
+ * @param input The input.
+ * @param type The object type to create.
+ * @return The parsed object.
+ * @throws ParseException Malformed input encountered.
+ */
+ public static <T> T from(String input, Class<T> type) throws
ParseException {
+ return DEFAULT.read(input, type);
+ }
+
+ /**
+ * Parses an XML input object to the specified Java type.
+ *
+ * <p>
+ * A shortcut for calling <c><jsf>DEFAULT</jsf>.read(<jv>input</jv>,
<jv>type</jv>)</c>.
+ *
+ * @param <T> The class type of the object being created.
+ * @param input
+ * The input.
+ * <br>Can be any of the following types:
+ * <ul>
+ * <li><jk>null</jk>
+ * <li>{@link Reader}
+ * <li>{@link CharSequence}
+ * <li>{@link InputStream} containing UTF-8 encoded text
(or charset defined by
+ * {@link
org.apache.juneau.parser.ReaderParser.Builder#streamCharset(Charset)} property
value).
+ * <li><code><jk>byte</jk>[]</code> containing UTF-8
encoded text (or charset defined by
+ * {@link
org.apache.juneau.parser.ReaderParser.Builder#streamCharset(Charset)} property
value).
+ * <li>{@link File} containing system encoded text (or
charset defined by
+ * {@link
org.apache.juneau.parser.ReaderParser.Builder#fileCharset(Charset)} property
value).
+ * </ul>
+ * @param type The object type to create.
+ * @return The parsed object.
+ * @throws ParseException Malformed input encountered.
+ * @throws IOException Thrown by underlying stream.
+ */
+ public static <T> T from(Object input, Class<T> type) throws
ParseException, IOException {
+ return DEFAULT.read(input, type);
+ }
+
+ /**
+ * Parses an XML input string to the specified Java type.
+ *
+ * <p>
+ * A shortcut for calling <c><jsf>DEFAULT</jsf>.read(<jv>input</jv>,
<jv>type</jv>, <jv>args</jv>)</c>.
+ *
+ * @param <T> The class type of the object to create.
+ * @param input The input.
+ * @param type
+ * The object type to create.
+ * <br>Can be any of the following: {@link ClassMeta}, {@link
Class}, {@link ParameterizedType}, {@link GenericArrayType}
+ * @param args
+ * The type arguments of the class if it's a collection or map.
+ * <br>Can be any of the following: {@link ClassMeta}, {@link
Class}, {@link ParameterizedType}, {@link GenericArrayType}
+ * <br>Ignored if the main type is not a map or collection.
+ * @return The parsed object.
+ * @throws ParseException Malformed input encountered.
+ * @see BeanSession#getClassMeta(Type,Type...) for argument syntax for
maps and collections.
+ */
+ public static <T> T from(String input, Type type, Type...args) throws
ParseException {
+ return DEFAULT.read(input, type, args);
+ }
+
+ /**
+ * Parses an XML input object to the specified Java type.
+ *
+ * <p>
+ * A shortcut for calling <c><jsf>DEFAULT</jsf>.read(<jv>input</jv>,
<jv>type</jv>, <jv>args</jv>)</c>.
+ *
+ * @param <T> The class type of the object to create.
+ * @param input
+ * The input.
+ * <br>Can be any of the following types:
+ * <ul>
+ * <li><jk>null</jk>
+ * <li>{@link Reader}
+ * <li>{@link CharSequence}
+ * <li>{@link InputStream} containing UTF-8 encoded text
(or charset defined by
+ * {@link
org.apache.juneau.parser.ReaderParser.Builder#streamCharset(Charset)} property
value).
+ * <li><code><jk>byte</jk>[]</code> containing UTF-8
encoded text (or charset defined by
+ * {@link
org.apache.juneau.parser.ReaderParser.Builder#streamCharset(Charset)} property
value).
+ * <li>{@link File} containing system encoded text (or
charset defined by
+ * {@link
org.apache.juneau.parser.ReaderParser.Builder#fileCharset(Charset)} property
value).
+ * </ul>
+ * @param type
+ * The object type to create.
+ * <br>Can be any of the following: {@link ClassMeta}, {@link
Class}, {@link ParameterizedType}, {@link GenericArrayType}
+ * @param args
+ * The type arguments of the class if it's a collection or map.
+ * <br>Can be any of the following: {@link ClassMeta}, {@link
Class}, {@link ParameterizedType}, {@link GenericArrayType}
+ * <br>Ignored if the main type is not a map or collection.
+ * @return The parsed object.
+ * @throws ParseException Malformed input encountered.
+ * @throws IOException Thrown by underlying stream.
+ * @see BeanSession#getClassMeta(Type,Type...) for argument syntax for
maps and collections.
+ */
+ public static <T> T from(Object input, Type type, Type...args) throws
ParseException, IOException {
+ return DEFAULT.read(input, type, args);
+ }
+
+ /**
+ * Serializes a Java object to an XML string.
+ *
+ * <p>
+ * A shortcut for calling
<c><jsf>DEFAULT</jsf>.write(<jv>object</jv>)</c>.
+ *
+ * @param object The object to serialize.
+ * @return
+ * The serialized object.
+ * @throws SerializeException If a problem occurred trying to convert
the output.
+ */
+ public static String to(Object object) throws SerializeException {
+ return DEFAULT.write(object);
+ }
+
+ /**
+ * Serializes a Java object to an XML output.
+ *
+ * <p>
+ * A shortcut for calling
<c><jsf>DEFAULT</jsf>.write(<jv>output</jv>)</c>.
+ *
+ * @param object The object to serialize.
+ * @param output
+ * The output object.
+ * <br>Can be any of the following types:
+ * <ul>
+ * <li>{@link Writer}
+ * <li>{@link OutputStream} - Output will be written as
UTF-8 encoded stream.
+ * <li>{@link File} - Output will be written as
system-default encoded stream.
+ * <li>{@link StringBuilder} - Output will be written to
the specified string builder.
+ * </ul>
+ * @throws SerializeException If a problem occurred trying to convert
the output.
+ * @throws IOException Thrown by underlying stream.
+ */
+ public static void to(Object object, Object output) throws
SerializeException, IOException {
+ DEFAULT.write(object, output);
+ }
}
diff --git a/juneau-doc/docs/Topics/02.juneau-marshall/03.jm.Marshalls.html
b/juneau-doc/docs/Topics/02.juneau-marshall/03.jm.Marshalls.html
index 5aa0a9b47..0ecf29bb4 100644
--- a/juneau-doc/docs/Topics/02.juneau-marshall/03.jm.Marshalls.html
+++ b/juneau-doc/docs/Topics/02.juneau-marshall/03.jm.Marshalls.html
@@ -50,7 +50,11 @@
| MyPojo <jv>myPojo</jv> =
Json.<jsf>DEFAULT</jsf>.read(<jv>string</jv>, MyPojo.<jk>class</jk>);
| String <jv>string</jv> =
Json.<jsf>DEFAULT</jsf>.write(<jv>myPojo</jv>);
</p>
-
+ <p class='bjava'>
+ | <jc>// Using shortcut methods.</jc>
+ | MyPojo <jv>myPojo</jv> =
Json.<jsf>from</jsf>(<jv>string</jv>, MyPojo.<jk>class</jk>);
+ | String <jv>string</jv> =
Json.<jsf>to</jsf>(<jv>myPojo</jv>);
+ </p>
<ul class='seealso'>
<li class='doclink'>{@doc g.LanguageSupport Language Support} -
Glossary of all supported languages.
</ul>