co.easimart.PointerEncoder Maven / Gradle / Ivy
package co.easimart;
import org.json.JSONObject;
/**
* Encodes {@link EasimartObjects} as pointers. If the object does not have an objectId, throws an
* exception.
*/
/** package */ class PointerEncoder extends PointerOrLocalIdEncoder {
// This class isn't really a Singleton, but since it has no state, it's more efficient to get the
// default instance.
private static final PointerEncoder INSTANCE = new PointerEncoder();
public static PointerEncoder get() {
return INSTANCE;
}
@Override
public JSONObject encodeRelatedObject(EasimartObject object) {
// Ensure the EasimartObject has an id so it can be encoded as a pointer.
if (object.getObjectId() == null) {
// object that hasn't been saved.
throw new IllegalStateException("unable to encode an association with an unsaved EasimartObject");
}
return super.encodeRelatedObject(object);
}
}