blob: 0468783006795aadebbf2c6d6d480ea411f093e5 [file] [log] [blame]
<!DOCTYPE HTML>
<html lang="en">
<head>
<!-- Generated by javadoc (18) -->
<title>StreamMarshaller (Apache Juneau 9.0.1)</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="description" content="declaration: package: org.apache.juneau.marshaller, class: StreamMarshaller">
<meta name="generator" content="javadoc/ClassWriterImpl">
<link rel="stylesheet" type="text/css" href="../../../../javadoc.css" title="Style">
<link rel="stylesheet" type="text/css" href="../../../../script-dir/jquery-ui.min.css" title="Style">
<link rel="stylesheet" type="text/css" href="../../../../jquery-ui.overrides.css" title="Style">
<script type="text/javascript" src="../../../../script.js"></script>
<script type="text/javascript" src="../../../../script-dir/jquery-3.5.1.min.js"></script>
<script type="text/javascript" src="../../../../script-dir/jquery-ui.min.js"></script>
</head>
<body class="class-declaration-page">
<script type="text/javascript">var evenRowColor = "even-row-color";
var oddRowColor = "odd-row-color";
var tableTab = "table-tab";
var activeTableTab = "active-table-tab";
var pathtoroot = "../../../../";
loadScripts(document, 'script');</script>
<noscript>
<div>JavaScript is disabled on your browser.</div>
</noscript>
<div class="flex-box">
<header role="banner" class="flex-header">
<nav role="navigation">
<!-- ========= START OF TOP NAVBAR ======= -->
<div class="top-nav" id="navbar-top"><button id="navbar-toggle-button" aria-controls="navbar-top" aria-expanded="false" aria-label="Toggle navigation links"><span class="nav-bar-toggle-icon"></span><span class="nav-bar-toggle-icon"></span><span class="nav-bar-toggle-icon"></span></button>
<div class="skip-nav"><a href="#skip-navbar-top" title="Skip navigation links">Skip navigation links</a></div>
<ul id="navbar-top-firstrow" class="nav-list" title="Navigation">
<li><a href="../../../../index.html">Overview</a></li>
<li><a href="package-summary.html">Package</a></li>
<li class="nav-bar-cell1-rev">Class</li>
<li><a href="package-tree.html">Tree</a></li>
<li><a href="../../../../deprecated-list.html">Deprecated</a></li>
<li><a href="../../../../index-all.html">Index</a></li>
<li><a href="../../../../help-doc.html#class">Help</a></li>
</ul>
<ul class="sub-nav-list-small">
<li>
<p>Summary:</p>
<ul>
<li>Nested</li>
<li>Field</li>
<li><a href="#constructor-summary">Constr</a></li>
<li><a href="#method-summary">Method</a></li>
</ul>
</li>
<li>
<p>Detail:</p>
<ul>
<li>Field</li>
<li><a href="#constructor-detail">Constr</a></li>
<li><a href="#method-detail">Method</a></li>
</ul>
</li>
</ul>
</div>
<div class="sub-nav">
<div id="navbar-sub-list">
<ul class="sub-nav-list">
<li>Summary:&nbsp;</li>
<li>Nested&nbsp;|&nbsp;</li>
<li>Field&nbsp;|&nbsp;</li>
<li><a href="#constructor-summary">Constr</a>&nbsp;|&nbsp;</li>
<li><a href="#method-summary">Method</a></li>
</ul>
<ul class="sub-nav-list">
<li>Detail:&nbsp;</li>
<li>Field&nbsp;|&nbsp;</li>
<li><a href="#constructor-detail">Constr</a>&nbsp;|&nbsp;</li>
<li><a href="#method-detail">Method</a></li>
</ul>
</div>
<div class="nav-list-search"><label for="search-input">SEARCH:</label>
<input type="text" id="search-input" disabled placeholder="Search">
<input type="reset" id="reset-button" disabled value="reset">
</div>
</div>
<!-- ========= END OF TOP NAVBAR ========= -->
<span class="skip-nav" id="skip-navbar-top"></span></nav>
</header>
<div class="flex-content">
<main role="main">
<!-- ======== START OF CLASS DATA ======== -->
<div class="header">
<div class="sub-title"><span class="package-label-in-type">Package</span>&nbsp;<a href="package-summary.html">org.apache.juneau.marshaller</a></div>
<h1 title="Class StreamMarshaller" class="title">Class StreamMarshaller</h1>
</div>
<div class="inheritance" title="Inheritance Tree"><a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html" title="class or interface in java.lang" class="external-link">java.lang.Object</a>
<div class="inheritance"><a href="Marshaller.html" title="class in org.apache.juneau.marshaller">org.apache.juneau.marshaller.Marshaller</a>
<div class="inheritance">org.apache.juneau.marshaller.StreamMarshaller</div>
</div>
</div>
<section class="class-description" id="class-description">
<dl class="notes">
<dt>Direct Known Subclasses:</dt>
<dd><code><a href="MsgPack.html" title="class in org.apache.juneau.marshaller">MsgPack</a></code></dd>
</dl>
<hr>
<div class="type-signature"><span class="modifiers">public class </span><span class="element-name"><a href="../../../../src-html/org/apache/juneau/marshaller/StreamMarshaller.html#line-29">StreamMarshaller</a></span>
<span class="extends-implements">extends <a href="Marshaller.html" title="class in org.apache.juneau.marshaller">Marshaller</a></span></div>
<div class="block">A subclass of <a href="Marshaller.html" title="class in org.apache.juneau.marshaller"><code>Marshaller</code></a> for stream-based serializers and parsers.
<h5 class='section'>See Also:</h5><ul>
<li class='link'><a class="doclink" href="../../../../index.html#jm.Marshallers">Marshallers</a>
</ul></div>
</section>
<section class="summary">
<ul class="summary-list">
<!-- ======== CONSTRUCTOR SUMMARY ======== -->
<li>
<section class="constructor-summary" id="constructor-summary">
<h2>Constructor Summary</h2>
<div class="caption"><span>Constructors</span></div>
<div class="summary-table two-column-summary">
<div class="table-header col-first">Constructor</div>
<div class="table-header col-last">Description</div>
<div class="col-constructor-name even-row-color"><code><a href="#%3Cinit%3E(org.apache.juneau.serializer.OutputStreamSerializer,org.apache.juneau.parser.InputStreamParser)" class="member-name-link">StreamMarshaller</a><wbr>(<a href="../serializer/OutputStreamSerializer.html" title="class in org.apache.juneau.serializer">OutputStreamSerializer</a>&nbsp;s,
<a href="../parser/InputStreamParser.html" title="class in org.apache.juneau.parser">InputStreamParser</a>&nbsp;p)</code></div>
<div class="col-last even-row-color">
<div class="block">Constructor.</div>
</div>
</div>
</section>
</li>
<!-- ========== METHOD SUMMARY =========== -->
<li>
<section class="method-summary" id="method-summary">
<h2>Method Summary</h2>
<div id="method-summary-table">
<div class="table-tabs" role="tablist" aria-orientation="horizontal"><button id="method-summary-table-tab0" role="tab" aria-selected="true" aria-controls="method-summary-table.tabpanel" tabindex="0" onkeydown="switchTab(event)" onclick="show('method-summary-table', 'method-summary-table', 3)" class="active-table-tab">All Methods</button><button id="method-summary-table-tab2" role="tab" aria-selected="false" aria-controls="method-summary-table.tabpanel" tabindex="-1" onkeydown="switchTab(event)" onclick="show('method-summary-table', 'method-summary-table-tab2', 3)" class="table-tab">Instance Methods</button><button id="method-summary-table-tab4" role="tab" aria-selected="false" aria-controls="method-summary-table.tabpanel" tabindex="-1" onkeydown="switchTab(event)" onclick="show('method-summary-table', 'method-summary-table-tab4', 3)" class="table-tab">Concrete Methods</button></div>
<div id="method-summary-table.tabpanel" role="tabpanel">
<div class="summary-table three-column-summary" aria-labelledby="method-summary-table-tab0">
<div class="table-header col-first">Modifier and Type</div>
<div class="table-header col-second">Method</div>
<div class="table-header col-last">Description</div>
<div class="col-first even-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab4"><code>final &lt;T&gt;&nbsp;T</code></div>
<div class="col-second even-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab4"><code><a href="#read(byte%5B%5D,java.lang.Class)" class="member-name-link">read</a><wbr>(byte[]&nbsp;input,
<a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Class.html" title="class or interface in java.lang" class="external-link">Class</a>&lt;T&gt;&nbsp;type)</code></div>
<div class="col-last even-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab4">
<div class="block">Same as <a href="Marshaller.html#read(java.lang.Object,java.lang.Class)"><code>Marshaller.read(Object,Class)</code></a> but reads from a byte array and thus doesn't throw an <c>IOException</c>.</div>
</div>
<div class="col-first odd-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab4"><code>final &lt;T&gt;&nbsp;T</code></div>
<div class="col-second odd-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab4"><code><a href="#read(byte%5B%5D,java.lang.reflect.Type,java.lang.reflect.Type...)" class="member-name-link">read</a><wbr>(byte[]&nbsp;input,
<a href="https://docs.oracle.com/javase/8/docs/api/java/lang/reflect/Type.html" title="class or interface in java.lang.reflect" class="external-link">Type</a>&nbsp;type,
<a href="https://docs.oracle.com/javase/8/docs/api/java/lang/reflect/Type.html" title="class or interface in java.lang.reflect" class="external-link">Type</a>...&nbsp;args)</code></div>
<div class="col-last odd-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab4">
<div class="block">Same as <a href="Marshaller.html#read(java.lang.Object,java.lang.reflect.Type,java.lang.reflect.Type...)"><code>Marshaller.read(Object,Type,Type...)</code></a> but reads from a byte array and thus doesn't throw an <c>IOException</c>.</div>
</div>
<div class="col-first even-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab4"><code>final byte[]</code></div>
<div class="col-second even-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab4"><code><a href="#write(java.lang.Object)" class="member-name-link">write</a><wbr>(<a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html" title="class or interface in java.lang" class="external-link">Object</a>&nbsp;o)</code></div>
<div class="col-last even-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab4">
<div class="block">Serializes a POJO directly to a <code><jk>byte</jk>[]</code>.</div>
</div>
</div>
</div>
</div>
<div class="inherited-list">
<h3 id="methods-inherited-from-class-org.apache.juneau.marshaller.Marshaller">Methods inherited from class&nbsp;org.apache.juneau.marshaller.<a href="Marshaller.html" title="class in org.apache.juneau.marshaller">Marshaller</a></h3>
<code><a href="Marshaller.html#getParser()">getParser</a>, <a href="Marshaller.html#getSerializer()">getSerializer</a>, <a href="Marshaller.html#read(java.lang.Object,java.lang.Class)">read</a>, <a href="Marshaller.html#read(java.lang.Object,java.lang.reflect.Type,java.lang.reflect.Type...)">read</a>, <a href="Marshaller.html#write(java.lang.Object,java.lang.Object)">write</a></code></div>
<div class="inherited-list">
<h3 id="methods-inherited-from-class-java.lang.Object">Methods inherited from class&nbsp;java.lang.<a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html" title="class or interface in java.lang" class="external-link">Object</a></h3>
<code><a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#clone()" title="class or interface in java.lang" class="external-link">clone</a>, <a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#equals(java.lang.Object)" title="class or interface in java.lang" class="external-link">equals</a>, <a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#finalize()" title="class or interface in java.lang" class="external-link">finalize</a>, <a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#getClass()" title="class or interface in java.lang" class="external-link">getClass</a>, <a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#hashCode()" title="class or interface in java.lang" class="external-link">hashCode</a>, <a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#notify()" title="class or interface in java.lang" class="external-link">notify</a>, <a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#notifyAll()" title="class or interface in java.lang" class="external-link">notifyAll</a>, <a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#toString()" title="class or interface in java.lang" class="external-link">toString</a>, <a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait()" title="class or interface in java.lang" class="external-link">wait</a>, <a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait(long)" title="class or interface in java.lang" class="external-link">wait</a>, <a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait(long,int)" title="class or interface in java.lang" class="external-link">wait</a></code></div>
</section>
</li>
</ul>
</section>
<section class="details">
<ul class="details-list">
<!-- ========= CONSTRUCTOR DETAIL ======== -->
<li>
<section class="constructor-details" id="constructor-detail">
<h2>Constructor Details</h2>
<ul class="member-list">
<li>
<section class="detail" id="&lt;init&gt;(org.apache.juneau.serializer.OutputStreamSerializer,org.apache.juneau.parser.InputStreamParser)">
<h3>StreamMarshaller</h3>
<div class="member-signature"><span class="modifiers">public</span>&nbsp;<span class="element-name"><a href="../../../../src-html/org/apache/juneau/marshaller/StreamMarshaller.html#line-48">StreamMarshaller</a></span><wbr><span class="parameters">(<a href="../serializer/OutputStreamSerializer.html" title="class in org.apache.juneau.serializer">OutputStreamSerializer</a>&nbsp;s,
<a href="../parser/InputStreamParser.html" title="class in org.apache.juneau.parser">InputStreamParser</a>&nbsp;p)</span></div>
<div class="block">Constructor.</div>
<dl class="notes">
<dt>Parameters:</dt>
<dd><code>s</code> - The serializer to use for serializing output.
<br>Must not be <jk>null</jk>.</dd>
<dd><code>p</code> - The parser to use for parsing input.
<br>Must not be <jk>null</jk>.</dd>
</dl>
</section>
</li>
</ul>
</section>
</li>
<!-- ============ METHOD DETAIL ========== -->
<li>
<section class="method-details" id="method-detail">
<h2>Method Details</h2>
<ul class="member-list">
<li>
<section class="detail" id="read(byte[],java.lang.Class)">
<h3>read</h3>
<div class="member-signature"><span class="modifiers">public final</span>&nbsp;<span class="type-parameters">&lt;T&gt;</span>&nbsp;<span class="return-type">T</span>&nbsp;<span class="element-name"><a href="../../../../src-html/org/apache/juneau/marshaller/StreamMarshaller.html#line-86">read</a></span><wbr><span class="parameters">(byte[]&nbsp;input,
<a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Class.html" title="class or interface in java.lang" class="external-link">Class</a>&lt;T&gt;&nbsp;type)</span>
throws <span class="exceptions"><a href="../parser/ParseException.html" title="class in org.apache.juneau.parser">ParseException</a></span></div>
<div class="block">Same as <a href="Marshaller.html#read(java.lang.Object,java.lang.Class)"><code>Marshaller.read(Object,Class)</code></a> 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'>
Marshaller <jv>marshaller</jv> = Json.<jsf>DEFAULT</jsf>;
<jc>// Parse into a string.</jc>
String <jv>string</jv> = <jv>marshaller</jv> .read(<jv>json</jv>, String.<jk>class</jk>);
<jc>// Parse into a bean.</jc>
MyBean <jv>bean</jv> = <jv>marshaller</jv> .read(<jv>json</jv>, MyBean.<jk>class</jk>);
<jc>// Parse into a bean array.</jc>
MyBean[] <jv>beanArray</jv> = <jv>marshaller</jv> .read(<jv>json</jv>, MyBean[].<jk>class</jk>);
<jc>// Parse into a linked-list of objects.</jc>
List <jv>list</jv> = <jv>marshaller</jv> .read(<jv>json</jv>, LinkedList.<jk>class</jk>);
<jc>// Parse into a map of object keys/values.</jc>
Map <jv>map</jv> = <jv>marshaller</jv> .read(<jv>json</jv>, TreeMap.<jk>class</jk>);
</p></div>
<dl class="notes">
<dt>Type Parameters:</dt>
<dd><code>T</code> - The class type of the object being created.</dd>
<dt>Parameters:</dt>
<dd><code>input</code> - The input.</dd>
<dd><code>type</code> - The object type to create.</dd>
<dt>Returns:</dt>
<dd>The parsed object.</dd>
<dt>Throws:</dt>
<dd><code><a href="../parser/ParseException.html" title="class in org.apache.juneau.parser">ParseException</a></code> - Malformed input encountered.</dd>
</dl>
</section>
</li>
<li>
<section class="detail" id="read(byte[],java.lang.reflect.Type,java.lang.reflect.Type...)">
<h3>read</h3>
<div class="member-signature"><span class="modifiers">public final</span>&nbsp;<span class="type-parameters">&lt;T&gt;</span>&nbsp;<span class="return-type">T</span>&nbsp;<span class="element-name"><a href="../../../../src-html/org/apache/juneau/marshaller/StreamMarshaller.html#line-110">read</a></span><wbr><span class="parameters">(byte[]&nbsp;input,
<a href="https://docs.oracle.com/javase/8/docs/api/java/lang/reflect/Type.html" title="class or interface in java.lang.reflect" class="external-link">Type</a>&nbsp;type,
<a href="https://docs.oracle.com/javase/8/docs/api/java/lang/reflect/Type.html" title="class or interface in java.lang.reflect" class="external-link">Type</a>...&nbsp;args)</span>
throws <span class="exceptions"><a href="../parser/ParseException.html" title="class in org.apache.juneau.parser">ParseException</a></span></div>
<div class="block">Same as <a href="Marshaller.html#read(java.lang.Object,java.lang.reflect.Type,java.lang.reflect.Type...)"><code>Marshaller.read(Object,Type,Type...)</code></a> but reads from a byte array and thus doesn't throw an <c>IOException</c>.</div>
<dl class="notes">
<dt>Type Parameters:</dt>
<dd><code>T</code> - The class type of the object to create.</dd>
<dt>Parameters:</dt>
<dd><code>input</code> - The input.</dd>
<dd><code>type</code> - The object type to create.
<br>Can be any of the following: <a href="../ClassMeta.html" title="class in org.apache.juneau"><code>ClassMeta</code></a>, <a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Class.html" title="class or interface in java.lang" class="external-link"><code>Class</code></a>, <a href="https://docs.oracle.com/javase/8/docs/api/java/lang/reflect/ParameterizedType.html" title="class or interface in java.lang.reflect" class="external-link"><code>ParameterizedType</code></a>, <a href="https://docs.oracle.com/javase/8/docs/api/java/lang/reflect/GenericArrayType.html" title="class or interface in java.lang.reflect" class="external-link"><code>GenericArrayType</code></a></dd>
<dd><code>args</code> - The type arguments of the class if it's a collection or map.
<br>Can be any of the following: <a href="../ClassMeta.html" title="class in org.apache.juneau"><code>ClassMeta</code></a>, <a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Class.html" title="class or interface in java.lang" class="external-link"><code>Class</code></a>, <a href="https://docs.oracle.com/javase/8/docs/api/java/lang/reflect/ParameterizedType.html" title="class or interface in java.lang.reflect" class="external-link"><code>ParameterizedType</code></a>, <a href="https://docs.oracle.com/javase/8/docs/api/java/lang/reflect/GenericArrayType.html" title="class or interface in java.lang.reflect" class="external-link"><code>GenericArrayType</code></a>
<br>Ignored if the main type is not a map or collection.</dd>
<dt>Returns:</dt>
<dd>The parsed object.</dd>
<dt>Throws:</dt>
<dd><code><a href="../parser/ParseException.html" title="class in org.apache.juneau.parser">ParseException</a></code> - Malformed input encountered.</dd>
<dt>See Also:</dt>
<dd>
<ul class="see-list-long">
<li><a href="../BeanSession.html#getClassMeta(java.lang.reflect.Type,java.lang.reflect.Type...)"><code>for argument syntax for maps and collections.</code></a></li>
</ul>
</dd>
</dl>
</section>
</li>
<li>
<section class="detail" id="write(java.lang.Object)">
<h3>write</h3>
<div class="member-signature"><span class="modifiers">public final</span>&nbsp;<span class="return-type">byte[]</span>&nbsp;<span class="element-name"><a href="../../../../src-html/org/apache/juneau/marshaller/StreamMarshaller.html#line-124">write</a></span><wbr><span class="parameters">(<a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html" title="class or interface in java.lang" class="external-link">Object</a>&nbsp;o)</span>
throws <span class="exceptions"><a href="../serializer/SerializeException.html" title="class in org.apache.juneau.serializer">SerializeException</a></span></div>
<div class="block">Serializes a POJO directly to a <code><jk>byte</jk>[]</code>.</div>
<dl class="notes">
<dt>Parameters:</dt>
<dd><code>o</code> - The object to serialize.</dd>
<dt>Returns:</dt>
<dd>The serialized object.</dd>
<dt>Throws:</dt>
<dd><code><a href="../serializer/SerializeException.html" title="class in org.apache.juneau.serializer">SerializeException</a></code> - If a problem occurred trying to convert the output.</dd>
</dl>
</section>
</li>
</ul>
</section>
</li>
</ul>
</section>
<!-- ========= END OF CLASS DATA ========= -->
</main>
<footer role="contentinfo">
<hr>
<p class="legal-copy"><small>Copyright &#169; 2016&#x2013;2022 <a href="https://www.apache.org/">The Apache Software Foundation</a>. All rights reserved.</small></p>
</footer>
</div>
</div>
</body>
</html>