@Override public Object encode(Object value, MappedField f) { if (value == null) return null; try { boolean useCompression = !f.getAnnotation(Serialized.class).disableCompression(); return Serializer.serialize(value, useCompression); } catch (IOException ex) { throw new RuntimeException(ex); } }
/** * Returns the name of the field's key-name for mongodb. */ private String getMappedFieldName() { if (hasAnnotation(Id.class) || hasAnnotation(javax.persistence.Id.class)) return Mapper.ID_KEY; else if (hasAnnotation(Property.class)) { Property mv = (Property) foundAnnotations.get(Property.class); if (!mv.value().equals(Mapper.IGNORED_FIELDNAME)) return mv.value(); } else if (hasAnnotation(Reference.class)) { Reference mr = (Reference) foundAnnotations.get(Reference.class); if (!mr.value().equals(Mapper.IGNORED_FIELDNAME)) return mr.value(); } else if (hasAnnotation(Embedded.class)) { Embedded me = (Embedded) foundAnnotations.get(Embedded.class); if (!me.value().equals(Mapper.IGNORED_FIELDNAME)) return me.value(); } else if (hasAnnotation(Serialized.class)) { Serialized me = (Serialized) foundAnnotations.get(Serialized.class); if (!me.value().equals(Mapper.IGNORED_FIELDNAME)) return me.value(); } else if (hasAnnotation(Version.class)) { Version me = (Version) foundAnnotations.get(Version.class); if (!me.value().equals(Mapper.IGNORED_FIELDNAME)) return me.value(); } return this.field.getName(); }
@Override public Object decode(Class targetClass, Object fromDBObject, MappedField f) throws MappingException { if (fromDBObject == null) return null; if (!((fromDBObject instanceof Binary) || (fromDBObject instanceof byte[]))) { throw new MappingException("The stored data is not a DBBinary or byte[] instance for " + f.getFullName() + " ; it is a " + fromDBObject.getClass().getName()); } try { boolean useCompression = !f.getAnnotation(Serialized.class).disableCompression(); return Serializer.deserialize(fromDBObject, useCompression); } catch (IOException e) { throw new MappingException("While deserializing to " + f.getFullName(), e); } catch (ClassNotFoundException e) { throw new MappingException("While deserializing to " + f.getFullName(), e); } }
return Serializer.serialize(value, !mf.getAnnotation(Serialized.class).disableCompression()); } catch (IOException e) { throw new RuntimeException(e);