/** * Serialize any object. See {@link BiMapper#deserializeObject(Object, BiDeserializer)} for more information. * * @param obj * @param <T> * * @return */ public <T> T serialize(Object obj) { return mapper.serialize(obj, this); }
/** * Try do serialize some object. Throws an exception if serialized form is tha same as not serialzied, as it means * that there is no suitable adapter to process. Be caeful because it will throw an exception also for the types * should not be serialized and this way are left intact. * * @param obj to try to serialize * @param <T> * * @return */ public <T> T serializeOrThrow(Object obj) { T result = mapper.serialize(obj, this); if (result == obj) throw new BiSerializationException("can't serialize " + obj); return result; } }
/** * Same as {@link #serialize(Object, BiSerializer)} with default {@link BiSerializer}. */ public @NonNull <T> T serialize(Object x) { return serialize(x, new BiSerializer(this)); }
synchronized public void check() throws Quantiser.QuantiserException { try { BiMapper mapper = BossBiMapper.getInstance(); MapDelta rootDelta = Delta.between(mapper.serialize(existing), mapper.serialize(changed)); MapDelta definitionDelta = (MapDelta) rootDelta.getChange("definition"); stateDelta = (MapDelta) rootDelta.getChange("state"); if (definitionDelta != null) { addError(ILLEGAL_CHANGE, "definition", "definition must not be changed"); } // check immutable root area // should be only one change here: state int allowedRootChanges = 1; Delta ch = rootDelta.getChange("api_level"); if( ch != null) { allowedRootChanges++; } // or can be changed section "transactional" Delta transactionalDelta = rootDelta.getChange("transactional"); if(transactionalDelta != null) { allowedRootChanges++; } if (rootDelta.getChanges().size() > allowedRootChanges) addError(ILLEGAL_CHANGE, "root", "root level changes are forbidden except the state"); // check only permitted changes in data checkStateChange(); } catch (ClassCastException e) { e.printStackTrace(); addError(FAILED_CHECK, "", "failed to compare, structure is broken or not supported"); } }