Package org.jboss.errai.marshalling.client.api

Source Code of org.jboss.errai.marshalling.client.api.MarshallerFramework

package org.jboss.errai.marshalling.client.api;

import com.google.gwt.core.client.GWT;
import com.google.gwt.json.client.JSONObject;
import org.jboss.errai.common.client.protocols.SerializationParts;

/**
* @author Mike Brock <cbrock@redhat.com>
*/
public class MarshallerFramework {
  private static final MarshallerFactory marshallerFactory;

  static {
    marshallerFactory = GWT.create(MarshallerFactory.class);
  }

  public static Object demarshallErraiJSON(JSONObject object) {
    MarshallingContext context = new MarshallingContext() {

      @Override
      public Marshaller<Object, Object> getMarshallerForType(String fqcn) {
        return marshallerFactory.getMarshaller(null, fqcn);
      }

      @Override
      public String determineTypeFor(String formatType, Object o) {
        JSONObject jsonObject = (JSONObject) o;
        return jsonObject.get(SerializationParts.ENCODED_TYPE).isString().stringValue();
      }
    };

    Marshaller<Object, Object> marshaller =
            marshallerFactory.getMarshaller(null, context.determineTypeFor(null, object));

    return marshaller.demarshall(object, context);

  }

}
TOP

Related Classes of org.jboss.errai.marshalling.client.api.MarshallerFramework

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.