Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ public static boolean canHandle(Type type) {

@Override
public Object deserializeFromRepresentation(Representation repr, Function<String, RepresentationRestorer> getRegisteredRestorer) {
if (repr == null)
return null;

//Create array
Object result = Array.newInstance(elementType, repr.list().size());

Expand All @@ -64,6 +67,9 @@ public Object deserializeFromRepresentation(Representation repr, Function<String

@Override
public Representation serializeToRepresentation(Object obj) {
if (obj == null)
return null;

ListRepresentation repr = new ListRepresentation();

for (int i=0; i<Array.getLength(obj); i++)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,15 @@ public static boolean canHandle(Type type) {

@Override
public Object deserializeFromRepresentation(Representation repr, Function<String, RepresentationRestorer> getRegisteredRestorer) {
if (repr == null)
return null;
return getRegisteredRestorer.apply(restorerString).restoreFromRepresentation(typeToRestore, repr);
}

@Override
public Representation serializeToRepresentation(Object object) {
if (object == null)
return null;
return ((Representable) object).getRepresentation();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,10 @@ public static boolean canHandle(Type collectionType) { //handles List|Set<anythi

@SuppressWarnings({"rawtypes", "unchecked"})
@Override
public Object deserializeFromRepresentation(Representation repr,
Function<String, RepresentationRestorer> getRegisteredRestorer) {
public Object deserializeFromRepresentation(Representation repr, Function<String, RepresentationRestorer> getRegisteredRestorer) {
if (repr == null)
return null;

Collection result = null;

//Try to call default constructor to create collection.
Expand Down Expand Up @@ -130,12 +132,19 @@ public Object deserializeFromRepresentation(Representation repr,

@Override
public Representation serializeToRepresentation(Object obj) {
if (obj == null)
return null;

if (!(obj instanceof List || obj instanceof Set))
throw new IllegalArgumentException("Cannot handle representation of "+obj.getClass().getName());

if (!(obj instanceof List)) { //shuffle elements to avoid order leak
obj = Arrays.asList(((Set<?>) obj).toArray());
Collections.shuffle((List<?>) obj);
}

ListRepresentation repr = new ListRepresentation();
for (Object inner : (Iterable<?>) obj) {
//TODO sort elements in case of a Set type to avoid leaking something.
// Or is that done by the Converter? No, cannot.
repr.put(elementHandler.serializeToRepresentation(inner));
}
return repr;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ public static boolean canHandle(Type mapType) { //handles Map<anything>.
@SuppressWarnings({"rawtypes", "unchecked"})
@Override
public Object deserializeFromRepresentation(Representation repr, Function<String, RepresentationRestorer> getRegisteredRestorer) {
if (repr == null)
return null;

Map result = null;

// Try to call default constructor to create collection.
Expand Down Expand Up @@ -141,8 +144,11 @@ public Object deserializeFromRepresentation(Representation repr, Function<String

@Override
public Representation serializeToRepresentation(Object obj) {
if (obj == null)
return null;
if (!(obj instanceof Map))
throw new IllegalArgumentException("Cannot handle representation of "+obj.getClass().getName());

MapRepresentation repr = new MapRepresentation();
((Map<?,?>) obj).forEach(
(k, v) -> repr.put(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ public static boolean canHandle(Type type) {
}

@Override
public Object deserializeFromRepresentation(Representation repr,
Function<String, RepresentationRestorer> getRegisteredRestorer) {
public Object deserializeFromRepresentation(Representation repr, Function<String, RepresentationRestorer> getRegisteredRestorer) {
if (repr == null) {
return null;
}
Expand Down