276 lines
12 KiB
HTML
276 lines
12 KiB
HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
|
<!--NewPage-->
|
|
<HTML>
|
|
<HEAD>
|
|
<!-- Generated by javadoc (build 1.6.0_65) on Thu Nov 20 01:11:54 PST 2014 -->
|
|
<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
|
<TITLE>
|
|
JsonAdapter (Gson 2.3.1 API)
|
|
</TITLE>
|
|
|
|
<META NAME="date" CONTENT="2014-11-20">
|
|
|
|
<LINK REL ="stylesheet" TYPE="text/css" HREF="../../../../stylesheet.css" TITLE="Style">
|
|
|
|
<SCRIPT type="text/javascript">
|
|
function windowTitle()
|
|
{
|
|
if (location.href.indexOf('is-external=true') == -1) {
|
|
parent.document.title="JsonAdapter (Gson 2.3.1 API)";
|
|
}
|
|
}
|
|
</SCRIPT>
|
|
<NOSCRIPT>
|
|
</NOSCRIPT>
|
|
|
|
</HEAD>
|
|
|
|
<BODY BGCOLOR="white" onload="windowTitle();">
|
|
<HR>
|
|
|
|
|
|
<!-- ========= START OF TOP NAVBAR ======= -->
|
|
<A NAME="navbar_top"><!-- --></A>
|
|
<A HREF="#skip-navbar_top" title="Skip navigation links"></A>
|
|
<TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0" SUMMARY="">
|
|
<TR>
|
|
<TD COLSPAN=2 BGCOLOR="#EEEEFF" CLASS="NavBarCell1">
|
|
<A NAME="navbar_top_firstrow"><!-- --></A>
|
|
<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3" SUMMARY="">
|
|
<TR ALIGN="center" VALIGN="top">
|
|
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../overview-summary.html"><FONT CLASS="NavBarFont1"><B>Overview</B></FONT></A> </TD>
|
|
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-summary.html"><FONT CLASS="NavBarFont1"><B>Package</B></FONT></A> </TD>
|
|
<TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> <FONT CLASS="NavBarFont1Rev"><B>Class</B></FONT> </TD>
|
|
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="class-use/JsonAdapter.html"><FONT CLASS="NavBarFont1"><B>Use</B></FONT></A> </TD>
|
|
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A> </TD>
|
|
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A> </TD>
|
|
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../index-all.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A> </TD>
|
|
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A> </TD>
|
|
</TR>
|
|
</TABLE>
|
|
</TD>
|
|
<TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM>
|
|
</EM>
|
|
</TD>
|
|
</TR>
|
|
|
|
<TR>
|
|
<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
|
|
<A HREF="../../../../com/google/gson/annotations/Expose.html" title="annotation in com.google.gson.annotations"><B>PREV CLASS</B></A>
|
|
<A HREF="../../../../com/google/gson/annotations/SerializedName.html" title="annotation in com.google.gson.annotations"><B>NEXT CLASS</B></A></FONT></TD>
|
|
<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
|
|
<A HREF="../../../../index.html?com/google/gson/annotations/JsonAdapter.html" target="_top"><B>FRAMES</B></A>
|
|
<A HREF="JsonAdapter.html" target="_top"><B>NO FRAMES</B></A>
|
|
<SCRIPT type="text/javascript">
|
|
<!--
|
|
if(window==top) {
|
|
document.writeln('<A HREF="../../../../allclasses-noframe.html"><B>All Classes</B></A>');
|
|
}
|
|
//-->
|
|
</SCRIPT>
|
|
<NOSCRIPT>
|
|
<A HREF="../../../../allclasses-noframe.html"><B>All Classes</B></A>
|
|
</NOSCRIPT>
|
|
|
|
|
|
</FONT></TD>
|
|
</TR>
|
|
<TR>
|
|
<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
|
|
SUMMARY: <A HREF="#annotation_type_required_element_summary">REQUIRED</A> | OPTIONAL</FONT></TD>
|
|
<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
|
|
DETAIL: <A HREF="#annotation_type_element_detail">ELEMENT</A></FONT></TD>
|
|
</TR>
|
|
</TABLE>
|
|
<A NAME="skip-navbar_top"></A>
|
|
<!-- ========= END OF TOP NAVBAR ========= -->
|
|
|
|
<HR>
|
|
<!-- ======== START OF CLASS DATA ======== -->
|
|
<H2>
|
|
<FONT SIZE="-1">
|
|
com.google.gson.annotations</FONT>
|
|
<BR>
|
|
Annotation Type JsonAdapter</H2>
|
|
<HR>
|
|
<DL>
|
|
<DT><PRE><FONT SIZE="-1"><A HREF="http://docs.oracle.com/javase/1.5.0/docs/api/java/lang/annotation/Retention.html?is-external=true" title="class or interface in java.lang.annotation">@Retention</A>(<A HREF="http://docs.oracle.com/javase/1.5.0/docs/api/java/lang/annotation/Retention.html?is-external=true#value()" title="class or interface in java.lang.annotation">value</A>=<A HREF="http://docs.oracle.com/javase/1.5.0/docs/api/java/lang/annotation/RetentionPolicy.html?is-external=true#RUNTIME" title="class or interface in java.lang.annotation">RUNTIME</A>)
|
|
<A HREF="http://docs.oracle.com/javase/1.5.0/docs/api/java/lang/annotation/Target.html?is-external=true" title="class or interface in java.lang.annotation">@Target</A>(<A HREF="http://docs.oracle.com/javase/1.5.0/docs/api/java/lang/annotation/Target.html?is-external=true#value()" title="class or interface in java.lang.annotation">value</A>={<A HREF="http://docs.oracle.com/javase/1.5.0/docs/api/java/lang/annotation/ElementType.html?is-external=true#TYPE" title="class or interface in java.lang.annotation">TYPE</A>,<A HREF="http://docs.oracle.com/javase/1.5.0/docs/api/java/lang/annotation/ElementType.html?is-external=true#FIELD" title="class or interface in java.lang.annotation">FIELD</A>})
|
|
</FONT>public @interface <B>JsonAdapter</B></DL>
|
|
</PRE>
|
|
|
|
<P>
|
|
An annotation that indicates the Gson <A HREF="../../../../com/google/gson/TypeAdapter.html" title="class in com.google.gson"><CODE>TypeAdapter</CODE></A> to use with a class
|
|
or field.
|
|
|
|
<p>Here is an example of how this annotation is used:</p>
|
|
<pre>
|
|
@JsonAdapter(UserJsonAdapter.class)
|
|
public class User {
|
|
public final String firstName, lastName;
|
|
private User(String firstName, String lastName) {
|
|
this.firstName = firstName;
|
|
this.lastName = lastName;
|
|
}
|
|
}
|
|
public class UserJsonAdapter extends TypeAdapter<User> {
|
|
@Override public void write(JsonWriter out, User user) throws IOException {
|
|
// implement write: combine firstName and lastName into name
|
|
out.beginObject();
|
|
out.name("name");
|
|
out.value(user.firstName + " " + user.lastName);
|
|
out.endObject();
|
|
// implement the write method
|
|
}
|
|
@Override public User read(JsonReader in) throws IOException {
|
|
// implement read: split name into firstName and lastName
|
|
in.beginObject();
|
|
in.nextName();
|
|
String[] nameParts = in.nextString().split(" ");
|
|
in.endObject();
|
|
return new User(nameParts[0], nameParts[1]);
|
|
}
|
|
}
|
|
</pre>
|
|
|
|
Since User class specified UserJsonAdapter.class in @JsonAdapter annotation, it
|
|
will automatically be invoked to serialize/deserialize User instances. <br>
|
|
|
|
<p> Here is an example of how to apply this annotation to a field.
|
|
<pre>
|
|
private static final class Gadget {
|
|
@JsonAdapter(UserJsonAdapter2.class)
|
|
final User user;
|
|
Gadget(User user) {
|
|
this.user = user;
|
|
}
|
|
}
|
|
</pre>
|
|
|
|
It's possible to specify different type adapters on a field, that
|
|
field's type, and in the <A HREF="../../../../com/google/gson/GsonBuilder.html" title="class in com.google.gson"><CODE>GsonBuilder</CODE></A>. Field
|
|
annotations take precedence over <code>GsonBuilder</code>-registered type
|
|
adapters, which in turn take precedence over annotated types.
|
|
|
|
<p>The class referenced by this annotation must be either a <A HREF="../../../../com/google/gson/TypeAdapter.html" title="class in com.google.gson"><CODE>TypeAdapter</CODE></A> or a <A HREF="../../../../com/google/gson/TypeAdapterFactory.html" title="interface in com.google.gson"><CODE>TypeAdapterFactory</CODE></A>. Using the factory interface
|
|
makes it possible to delegate to the enclosing <code>Gson</code> instance.
|
|
<P>
|
|
|
|
<P>
|
|
<DL>
|
|
<DT><B>Since:</B></DT>
|
|
<DD>2.3</DD>
|
|
<DT><B>Author:</B></DT>
|
|
<DD>Inderjeet Singh, Joel Leitch, Jesse Wilson</DD>
|
|
</DL>
|
|
<HR>
|
|
|
|
<P>
|
|
<!-- =========== ANNOTATION TYPE REQUIRED MEMBER SUMMARY =========== -->
|
|
|
|
<A NAME="annotation_type_required_element_summary"><!-- --></A>
|
|
<TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
|
|
<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
|
|
<TH ALIGN="left" COLSPAN="2"><FONT SIZE="+2">
|
|
<B>Required Element Summary</B></FONT></TH>
|
|
</TR>
|
|
<TR BGCOLOR="white" CLASS="TableRowColor">
|
|
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
|
|
<CODE> <A HREF="http://docs.oracle.com/javase/1.5.0/docs/api/java/lang/Class.html?is-external=true" title="class or interface in java.lang">Class</A><?></CODE></FONT></TD>
|
|
<TD><CODE><B><A HREF="../../../../com/google/gson/annotations/JsonAdapter.html#value()">value</A></B></CODE>
|
|
|
|
<BR>
|
|
Either a <A HREF="../../../../com/google/gson/TypeAdapter.html" title="class in com.google.gson"><CODE>TypeAdapter</CODE></A> or <A HREF="../../../../com/google/gson/TypeAdapterFactory.html" title="interface in com.google.gson"><CODE>TypeAdapterFactory</CODE></A>.</TD>
|
|
</TR>
|
|
</TABLE>
|
|
|
|
<P>
|
|
|
|
<!-- ============ ANNOTATION TYPE MEMBER DETAIL =========== -->
|
|
|
|
<A NAME="annotation_type_element_detail"><!-- --></A>
|
|
<TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
|
|
<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
|
|
<TH ALIGN="left" COLSPAN="1"><FONT SIZE="+2">
|
|
<B>Element Detail</B></FONT></TH>
|
|
</TR>
|
|
</TABLE>
|
|
|
|
<A NAME="value()"><!-- --></A><H3>
|
|
value</H3>
|
|
<PRE>
|
|
public abstract <A HREF="http://docs.oracle.com/javase/1.5.0/docs/api/java/lang/Class.html?is-external=true" title="class or interface in java.lang">Class</A><?> <B>value</B></PRE>
|
|
<DL>
|
|
<DD>Either a <A HREF="../../../../com/google/gson/TypeAdapter.html" title="class in com.google.gson"><CODE>TypeAdapter</CODE></A> or <A HREF="../../../../com/google/gson/TypeAdapterFactory.html" title="interface in com.google.gson"><CODE>TypeAdapterFactory</CODE></A>.
|
|
<P>
|
|
<DD><DL>
|
|
</DL>
|
|
</DD>
|
|
<DD><DL>
|
|
</DL>
|
|
</DL>
|
|
<!-- ========= END OF CLASS DATA ========= -->
|
|
<HR>
|
|
|
|
|
|
<!-- ======= START OF BOTTOM NAVBAR ====== -->
|
|
<A NAME="navbar_bottom"><!-- --></A>
|
|
<A HREF="#skip-navbar_bottom" title="Skip navigation links"></A>
|
|
<TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0" SUMMARY="">
|
|
<TR>
|
|
<TD COLSPAN=2 BGCOLOR="#EEEEFF" CLASS="NavBarCell1">
|
|
<A NAME="navbar_bottom_firstrow"><!-- --></A>
|
|
<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3" SUMMARY="">
|
|
<TR ALIGN="center" VALIGN="top">
|
|
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../overview-summary.html"><FONT CLASS="NavBarFont1"><B>Overview</B></FONT></A> </TD>
|
|
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-summary.html"><FONT CLASS="NavBarFont1"><B>Package</B></FONT></A> </TD>
|
|
<TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> <FONT CLASS="NavBarFont1Rev"><B>Class</B></FONT> </TD>
|
|
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="class-use/JsonAdapter.html"><FONT CLASS="NavBarFont1"><B>Use</B></FONT></A> </TD>
|
|
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A> </TD>
|
|
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A> </TD>
|
|
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../index-all.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A> </TD>
|
|
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A> </TD>
|
|
</TR>
|
|
</TABLE>
|
|
</TD>
|
|
<TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM>
|
|
</EM>
|
|
</TD>
|
|
</TR>
|
|
|
|
<TR>
|
|
<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
|
|
<A HREF="../../../../com/google/gson/annotations/Expose.html" title="annotation in com.google.gson.annotations"><B>PREV CLASS</B></A>
|
|
<A HREF="../../../../com/google/gson/annotations/SerializedName.html" title="annotation in com.google.gson.annotations"><B>NEXT CLASS</B></A></FONT></TD>
|
|
<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
|
|
<A HREF="../../../../index.html?com/google/gson/annotations/JsonAdapter.html" target="_top"><B>FRAMES</B></A>
|
|
<A HREF="JsonAdapter.html" target="_top"><B>NO FRAMES</B></A>
|
|
<SCRIPT type="text/javascript">
|
|
<!--
|
|
if(window==top) {
|
|
document.writeln('<A HREF="../../../../allclasses-noframe.html"><B>All Classes</B></A>');
|
|
}
|
|
//-->
|
|
</SCRIPT>
|
|
<NOSCRIPT>
|
|
<A HREF="../../../../allclasses-noframe.html"><B>All Classes</B></A>
|
|
</NOSCRIPT>
|
|
|
|
|
|
</FONT></TD>
|
|
</TR>
|
|
<TR>
|
|
<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
|
|
SUMMARY: <A HREF="#annotation_type_required_element_summary">REQUIRED</A> | OPTIONAL</FONT></TD>
|
|
<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
|
|
DETAIL: <A HREF="#annotation_type_element_detail">ELEMENT</A></FONT></TD>
|
|
</TR>
|
|
</TABLE>
|
|
<A NAME="skip-navbar_bottom"></A>
|
|
<!-- ======== END OF BOTTOM NAVBAR ======= -->
|
|
|
|
<HR>
|
|
Copyright © 2008–2014 <a href="http://www.google.com">Google, Inc.</a>. All rights reserved.
|
|
</BODY>
|
|
</HTML>
|