for( AssociationDescriptor associationType : entityDescriptor.state().associations() )
{
try
{
Object jsonValue = assocs.get( associationType.qualifiedName().name() );
EntityReference value = jsonValue == JSONObject.NULL ? null : EntityReference.parseEntityReference(
(String) jsonValue );
associations.put( associationType.qualifiedName(), value );
}
catch( JSONException e )
{
// Association not found, default it to null
associations.put( associationType.qualifiedName(), null );
status = EntityStatus.UPDATED;
}
}
JSONObject manyAssocs = jsonObject.getJSONObject( "manyassociations" );
Map<QualifiedName, List<EntityReference>> manyAssociations = new HashMap<QualifiedName, List<EntityReference>>();
for( AssociationDescriptor manyAssociationType : entityDescriptor.state().manyAssociations() )
{
List<EntityReference> references = new ArrayList<EntityReference>();
try
{
JSONArray jsonValues = manyAssocs.getJSONArray( manyAssociationType.qualifiedName().name() );
for( int i = 0; i < jsonValues.length(); i++ )
{
Object jsonValue = jsonValues.getString( i );
EntityReference value = jsonValue == JSONObject.NULL ? null : EntityReference.parseEntityReference(
(String) jsonValue );
references.add( value );
}
manyAssociations.put( manyAssociationType.qualifiedName(), references );
}