Created
June 25, 2015 01:25
-
-
Save bdb1234/1f6623897bdfe3f8a710 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.zoosk.zoosk.data.objects.json; | |
import java.util.List; | |
import com.zoosk.zaframework.lang.JSONArray; | |
import com.zoosk.zaframework.lang.JSONObject; | |
class TestObject extends ZObject { | |
private enum DescriptorKey implements ZObject.DescriptorKey { | |
ALPHANUMERIC_LIST, | |
PRIMITIVE_ALPHANUMERIC, | |
PRIMITIVE_STRING, | |
STRING_SET; | |
} | |
public TestObject(JSONObject jsonObject) { | |
super(jsonObject); | |
} | |
@Override | |
protected Class<? extends DescriptorKey> putDescriptors(DescriptorMap descriptorMap) { | |
descriptorMap.put(DescriptorKey.PRIMITIVE_ALPHANUMERIC, String.class, "primitive_alphanumeric"); | |
descriptorMap.put(DescriptorKey.PRIMITIVE_STRING, String.class, "primitive_string"); | |
descriptorMap.put(DescriptorKey.STRING_SET, new ZObject.SetDescriptor<String>("string_set", "string") { | |
@Override | |
protected void populateList(JSONArray array, Set<String> listToPopulate) { | |
for (JSONObject jsonObject : array) { | |
listToPopulate.add(new String(jsonObject.getJSONObject("value")); | |
} | |
} | |
}); | |
descriptorMap.put(DescriptorKey.ALPHANUMERIC_LIST, new ZObject.ListDescriptor<AlphanumericListItem>("alphanumeric_list", "list_item") { | |
@Override | |
protected void populateList(JSONArray array, List<AlphanumericListItem> listToPopulate) { | |
for (JSONObject jsonObject : array) { | |
listToPopulate.add(new AlphanumericListItem(jsonObject)); | |
} | |
} | |
}); | |
return DescriptorKey.class; | |
} | |
@SuppressedWarning("unchecked") | |
public List<AlphanumericListItem> getAlphanumericListItem() { | |
return (List<AlphanumericListItem>) this.getList(DescriptorKey.ALPHANUMERIC_LIST); | |
} | |
public String getPrimitiveAlphanumeric() { | |
return this.getString(DescriptorKey.PRIMITIVE_ALPHANUMERIC); | |
} | |
public String getPrimitiveString() { | |
return this.getString(DescriptorKey.PRIMITIVE_STRING); | |
} | |
@SuppressedWarning("unchecked") | |
public Set<String> getStringSet() { | |
return (Set<String>) this.getSet(DescriptorKey.STRING_SET); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment