Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package org.s1.objects;
 
 
 import java.util.Date;
 import java.util.Map;

Object Wire helper

You need to convert some classes (Dates) to serializable format

Simple types are serialized in string format for instance /Date(1389439481222)/

Supported types:

public class ObjectWire {

    
Format Java Classes into strings version

Parameters:
json
Returns:
    static Map<StringObjecttoWire(Map<StringObjectjson) {
        return (Map<StringObject>) ObjectIterator.iterate(jsonnew Closure<ObjectIterator.IterateBeanObject>() {
            @Override
            public Object call(ObjectIterator.IterateBean i) {
                try {
                    if (i.getValue() instanceof Date) {
                        return "/Date(" + ((Datei.getValue()).getTime() + ")/";
                    }
                } catch (Exception e) {
                }
                return i.getValue();
            }
        });
    }

    
Parse simple types into Java Classes

Parameters:
json
Returns:
    static Map<StringObjectfromWire(Map<StringObjectjson) {
        return (Map<StringObject>) ObjectIterator.iterate(jsonnew Closure<ObjectIterator.IterateBeanObject>() {
            @Override
            public Object call(ObjectIterator.IterateBean i) {
                if (i.getValue() instanceof String) {
                    String s = (Stringi.getValue();
                    if (s.startsWith("/") && s.endsWith("/")) {
                        s = s.substring(1, s.length() - 1);
                        String type = s.substring(0, s.indexOf("("));
                        String value = s.substring(s.indexOf("(") + 1,
                                s.lastIndexOf(")"));
                        if ("Date".equalsIgnoreCase(type)) {
                            return ObjectType.cast(valueDate.class);
                        }
                    }
                }
                return i.getValue();
            }
        });
    }
New to GrepCode? Check out our FAQ X