diff options
author | Jesse Wilson <jesse@swank.ca> | 2011-12-31 20:53:38 +0000 |
---|---|---|
committer | Jesse Wilson <jesse@swank.ca> | 2011-12-31 20:53:38 +0000 |
commit | c4ea9a3d87f4d3098f9c614afe5fe42a3e6c2138 (patch) | |
tree | 2019a94d3aa5df7f92fc728e7702d905d2bcfeb5 /gson/docs/javadocs/com/google/gson/ExclusionStrategy.html | |
parent | caf64dbf55f6de7ec7e32a3a57d663b99ca08db1 (diff) | |
download | android_external_gson-c4ea9a3d87f4d3098f9c614afe5fe42a3e6c2138.tar.gz android_external_gson-c4ea9a3d87f4d3098f9c614afe5fe42a3e6c2138.tar.bz2 android_external_gson-c4ea9a3d87f4d3098f9c614afe5fe42a3e6c2138.zip |
New Javadocs for Gson 2.1.
Diffstat (limited to 'gson/docs/javadocs/com/google/gson/ExclusionStrategy.html')
-rw-r--r-- | gson/docs/javadocs/com/google/gson/ExclusionStrategy.html | 305 |
1 files changed, 305 insertions, 0 deletions
diff --git a/gson/docs/javadocs/com/google/gson/ExclusionStrategy.html b/gson/docs/javadocs/com/google/gson/ExclusionStrategy.html new file mode 100644 index 00000000..443a44be --- /dev/null +++ b/gson/docs/javadocs/com/google/gson/ExclusionStrategy.html @@ -0,0 +1,305 @@ +<!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_26) on Sat Dec 31 12:52:46 PST 2011 --> +<META http-equiv="Content-Type" content="text/html; charset=UTF-8"> +<TITLE> +ExclusionStrategy (Gson 2.1 API) +</TITLE> + +<META NAME="date" CONTENT="2011-12-31"> + +<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="ExclusionStrategy (Gson 2.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/ExclusionStrategy.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"> + PREV CLASS + <A HREF="../../../com/google/gson/FieldAttributes.html" title="class in com.google.gson"><B>NEXT CLASS</B></A></FONT></TD> +<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2"> + <A HREF="../../../index.html?com/google/gson/ExclusionStrategy.html" target="_top"><B>FRAMES</B></A> + <A HREF="ExclusionStrategy.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: NESTED | FIELD | CONSTR | <A HREF="#method_summary">METHOD</A></FONT></TD> +<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2"> +DETAIL: FIELD | CONSTR | <A HREF="#method_detail">METHOD</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</FONT> +<BR> +Interface ExclusionStrategy</H2> +<HR> +<DL> +<DT><PRE>public interface <B>ExclusionStrategy</B></DL> +</PRE> + +<P> +A strategy (or policy) definition that is used to decide whether or not a field or top-level + class should be serialized or deserialized as part of the JSON output/input. For serialization, + if the <A HREF="../../../com/google/gson/ExclusionStrategy.html#shouldSkipClass(java.lang.Class)"><CODE>shouldSkipClass(Class)</CODE></A> method returns false then that class or field type + will not be part of the JSON output. For deserialization, if <A HREF="../../../com/google/gson/ExclusionStrategy.html#shouldSkipClass(java.lang.Class)"><CODE>shouldSkipClass(Class)</CODE></A> + returns false, then it will not be set as part of the Java object structure. + + <p>The following are a few examples that shows how you can use this exclusion mechanism. + + <p><strong>Exclude fields and objects based on a particular class type:</strong> + <pre class="code"> + private static class SpecificClassExclusionStrategy implements ExclusionStrategy { + private final Class<?> excludedThisClass; + + public SpecificClassExclusionStrategy(Class<?> excludedThisClass) { + this.excludedThisClass = excludedThisClass; + } + + public boolean shouldSkipClass(Class<?> clazz) { + return excludedThisClass.equals(clazz); + } + + public boolean shouldSkipField(FieldAttributes f) { + return excludedThisClass.equals(f.getDeclaredClass()); + } + } + </pre> + + <p><strong>Excludes fields and objects based on a particular annotation:</strong> + <pre class="code"> + public @interface FooAnnotation { + // some implementation here + } + + // Excludes any field (or class) that is tagged with an "@FooAnnotation" + private static class FooAnnotationExclusionStrategy implements ExclusionStrategy { + public boolean shouldSkipClass(Class<?> clazz) { + return clazz.getAnnotation(FooAnnotation.class) != null; + } + + public boolean shouldSkipField(FieldAttributes f) { + return f.getAnnotation(FooAnnotation.class) != null; + } + } + </pre> + + <p>Now if you want to configure <code>Gson</code> to use a user defined exclusion strategy, then + the <code>GsonBuilder</code> is required. The following is an example of how you can use the + <code>GsonBuilder</code> to configure Gson to use one of the above sample: + <pre class="code"> + ExclusionStrategy excludeStrings = new UserDefinedExclusionStrategy(String.class); + Gson gson = new GsonBuilder() + .setExclusionStrategies(excludeStrings) + .create(); + </pre> + + <p>For certain model classes, you may only want to serialize a field, but exclude it for + deserialization. To do that, you can write an <code>ExclusionStrategy</code> as per normal; + however, you would register it with the + <A HREF="../../../com/google/gson/GsonBuilder.html#addDeserializationExclusionStrategy(com.google.gson.ExclusionStrategy)"><CODE>GsonBuilder.addDeserializationExclusionStrategy(ExclusionStrategy)</CODE></A> method. + For example: + <pre class="code"> + ExclusionStrategy excludeStrings = new UserDefinedExclusionStrategy(String.class); + Gson gson = new GsonBuilder() + .addDeserializationExclusionStrategy(excludeStrings) + .create(); + </pre> +<P> + +<P> +<DL> +<DT><B>Since:</B></DT> + <DD>1.4</DD> +<DT><B>Author:</B></DT> + <DD>Inderjeet Singh, Joel Leitch</DD> +<DT><B>See Also:</B><DD><A HREF="../../../com/google/gson/GsonBuilder.html#setExclusionStrategies(com.google.gson.ExclusionStrategy...)"><CODE>GsonBuilder.setExclusionStrategies(ExclusionStrategy...)</CODE></A>, +<A HREF="../../../com/google/gson/GsonBuilder.html#addDeserializationExclusionStrategy(com.google.gson.ExclusionStrategy)"><CODE>GsonBuilder.addDeserializationExclusionStrategy(ExclusionStrategy)</CODE></A>, +<A HREF="../../../com/google/gson/GsonBuilder.html#addSerializationExclusionStrategy(com.google.gson.ExclusionStrategy)"><CODE>GsonBuilder.addSerializationExclusionStrategy(ExclusionStrategy)</CODE></A></DL> +<HR> + +<P> + +<!-- ========== METHOD SUMMARY =========== --> + +<A NAME="method_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>Method Summary</B></FONT></TH> +</TR> +<TR BGCOLOR="white" CLASS="TableRowColor"> +<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"> +<CODE> boolean</CODE></FONT></TD> +<TD><CODE><B><A HREF="../../../com/google/gson/ExclusionStrategy.html#shouldSkipClass(java.lang.Class)">shouldSkipClass</A></B>(<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><?> clazz)</CODE> + +<BR> + </TD> +</TR> +<TR BGCOLOR="white" CLASS="TableRowColor"> +<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"> +<CODE> boolean</CODE></FONT></TD> +<TD><CODE><B><A HREF="../../../com/google/gson/ExclusionStrategy.html#shouldSkipField(com.google.gson.FieldAttributes)">shouldSkipField</A></B>(<A HREF="../../../com/google/gson/FieldAttributes.html" title="class in com.google.gson">FieldAttributes</A> f)</CODE> + +<BR> + </TD> +</TR> +</TABLE> + +<P> + +<!-- ============ METHOD DETAIL ========== --> + +<A NAME="method_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>Method Detail</B></FONT></TH> +</TR> +</TABLE> + +<A NAME="shouldSkipField(com.google.gson.FieldAttributes)"><!-- --></A><H3> +shouldSkipField</H3> +<PRE> +boolean <B>shouldSkipField</B>(<A HREF="../../../com/google/gson/FieldAttributes.html" title="class in com.google.gson">FieldAttributes</A> f)</PRE> +<DL> +<DD><DL> +<DT><B>Parameters:</B><DD><CODE>f</CODE> - the field object that is under test +<DT><B>Returns:</B><DD>true if the field should be ignored; otherwise false</DL> +</DD> +</DL> +<HR> + +<A NAME="shouldSkipClass(java.lang.Class)"><!-- --></A><H3> +shouldSkipClass</H3> +<PRE> +boolean <B>shouldSkipClass</B>(<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><?> clazz)</PRE> +<DL> +<DD><DL> +<DT><B>Parameters:</B><DD><CODE>clazz</CODE> - the class object that is under test +<DT><B>Returns:</B><DD>true if the class should be ignored; otherwise false</DL> +</DD> +</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/ExclusionStrategy.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"> + PREV CLASS + <A HREF="../../../com/google/gson/FieldAttributes.html" title="class in com.google.gson"><B>NEXT CLASS</B></A></FONT></TD> +<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2"> + <A HREF="../../../index.html?com/google/gson/ExclusionStrategy.html" target="_top"><B>FRAMES</B></A> + <A HREF="ExclusionStrategy.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: NESTED | FIELD | CONSTR | <A HREF="#method_summary">METHOD</A></FONT></TD> +<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2"> +DETAIL: FIELD | CONSTR | <A HREF="#method_detail">METHOD</A></FONT></TD> +</TR> +</TABLE> +<A NAME="skip-navbar_bottom"></A> +<!-- ======== END OF BOTTOM NAVBAR ======= --> + +<HR> +Copyright © 2008-2011 <a href="http://www.google.com">Google, Inc.</a>. All Rights Reserved. +</BODY> +</HTML> |