com.ecwid.mailchimp
Class MailChimpObject

java.lang.Object
  extended by java.util.AbstractMap<String,Object>
      extended by com.ecwid.mailchimp.MailChimpObject
All Implemented Interfaces:
Serializable, Map<String,Object>
Direct Known Subclasses:
AccountAppliedReward, AccountContactDetails, AccountDetails, AccountModuleDetails, AccountOrderDetails, AccountRewardCounter, AccountRewardDetails, AccountRewardReferral, ApikeyInfo, BatchError, BatchSubscribeInfo, BatchSubscribeResult, BatchUnsubscribeResult, DummyResult, EcommOrderInfo, EcommOrderItemInfo, Email, InterestGroup, InterestGroup, InterestGrouping, InterestGrouping, InterestGroupingAddResult, ListBatchError, ListBatchSubscribeResult, ListBatchUnsubscribeResult, ListInformation, ListMemberInfoResult, ListMembersResult, ListMethod.Filters, ListMethodResult, ListMethodResult.Data, ListMethodResult.Error, ListMethodResult.Stats, ListsMethodFilters, ListsResult, ListStats, MailChimpMethod, MemberInfo, MemberInfoData, MemberInfoError, MemberInfoGroup, MemberInfoGrouping, MemberInfoMerges, MemberInfoResult, MembersResult, MergeVarInfo, OrderInfo, OrderItemInfo, ShortMemberInfo, StaticSegmentInfo, StaticSegmentMembersAddErrors, StaticSegmentMembersInfo, TemplateInformation, TemplatesMethodInactives, TemplatesMethodTypes, TemplatesResult

public class MailChimpObject
extends AbstractMap<String,Object>
implements Serializable

Base class for all objects wrapping MailChimp API calls. Since this object is generally a map, its mappings are used to serilize/deserialize the object to/from JSON.

Some entries in the map are regular mappings, whereas others are reflective ones. Reflective mappings are represented by fields marked with the MailChimpObject.Field annotation. Changes in such fields are reflected in the map and vice versa.

Reflective mappings cannot be removed from this map.

Author:
Vasily Karyaev
See Also:
Serialized Form

Nested Class Summary
protected static interface MailChimpObject.Field
          Marks fields to be serialized/deserialed to/from JSON.
 
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K,V>
 
Nested classes/interfaces inherited from interface java.util.Map
Map.Entry<K,V>
 
Constructor Summary
MailChimpObject()
          Default constructior.
 
Method Summary
<T extends MailChimpObject>
T
as(Class<T> clazz)
          Converts this object to another object of class clazz.
 void clear()
          Unsupported operation.
 boolean containsKey(Object key)
           
 Set<Map.Entry<String,Object>> entrySet()
           
static
<T extends MailChimpObject>
T
fromJson(String json, Class<T> clazz)
          Deserializes an object from JSON.
 Object get(Object key)
           
 Map<String,Type> getReflectiveMappingTypes()
          Get desciption of the reflective mappings in this object.
static Map<String,Type> getReflectiveMappingTypes(Class<? extends MailChimpObject> clazz)
          Get desciption of the reflective mappings in class clazz.
 Set<String> keySet()
           
 Object put(String key, Object value)
           
 Object remove(Object key)
          Removes a regular mapping for a key from this map if it is present.
 int size()
           
 String toJson()
          Serializes this object to JSON.
 
Methods inherited from class java.util.AbstractMap
clone, containsValue, equals, hashCode, isEmpty, putAll, toString, values
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

MailChimpObject

public MailChimpObject()
Default constructior.

Method Detail

getReflectiveMappingTypes

public static Map<String,Type> getReflectiveMappingTypes(Class<? extends MailChimpObject> clazz)
Get desciption of the reflective mappings in class clazz.

Returns:
map in which keys are the mapping keys, and values are the corresponding field types.

getReflectiveMappingTypes

public Map<String,Type> getReflectiveMappingTypes()
Get desciption of the reflective mappings in this object.

Returns:
map in which keys are the mapping keys, and values are the corresponding field types.

get

public Object get(Object key)
Specified by:
get in interface Map<String,Object>
Overrides:
get in class AbstractMap<String,Object>

put

public Object put(String key,
                  Object value)
Specified by:
put in interface Map<String,Object>
Overrides:
put in class AbstractMap<String,Object>

remove

public Object remove(Object key)
Removes a regular mapping for a key from this map if it is present.

Specified by:
remove in interface Map<String,Object>
Overrides:
remove in class AbstractMap<String,Object>
Parameters:
key - key for a regular mapping
Returns:
the previous value associated with key, or null if there was no mapping for key
Throws:
IllegalArgumentException - if key is associated with a reflective mapping

containsKey

public boolean containsKey(Object key)
Specified by:
containsKey in interface Map<String,Object>
Overrides:
containsKey in class AbstractMap<String,Object>

size

public int size()
Specified by:
size in interface Map<String,Object>
Overrides:
size in class AbstractMap<String,Object>

clear

public void clear()
Unsupported operation. Since reflective mappings cannot be removed, this operation is not supported.

Specified by:
clear in interface Map<String,Object>
Overrides:
clear in class AbstractMap<String,Object>

keySet

public Set<String> keySet()
Specified by:
keySet in interface Map<String,Object>
Overrides:
keySet in class AbstractMap<String,Object>

entrySet

public Set<Map.Entry<String,Object>> entrySet()
Specified by:
entrySet in interface Map<String,Object>
Specified by:
entrySet in class AbstractMap<String,Object>

toJson

public final String toJson()
Serializes this object to JSON.


fromJson

public static <T extends MailChimpObject> T fromJson(String json,
                                                     Class<T> clazz)
Deserializes an object from JSON.

Throws:
IllegalArgumentException - if json cannot be deserialized to an object of class clazz.

as

public <T extends MailChimpObject> T as(Class<T> clazz)
Converts this object to another object of class clazz.

Returns:
a new object of the specified class.


Copyright © 2012-2014 Ecwid, Inc. All Rights Reserved.