Package com.changestuffs.server.utils

Source Code of com.changestuffs.server.utils.DtoToJson

package com.changestuffs.server.utils;

import com.changestuffs.shared.constants.MessageType;
import com.changestuffs.shared.dto.IMessageResponse;
import com.changestuffs.shared.dto.MessageResponse;
import com.changestuffs.shared.factory.MyAutoBeanFactory;
import com.google.inject.Singleton;
import com.google.web.bindery.autobean.shared.AutoBean;
import com.google.web.bindery.autobean.shared.AutoBeanCodex;
import com.google.web.bindery.autobean.vm.AutoBeanFactorySource;

@Singleton
public class DtoToJson {

  public String getJson(String body, String from, MessageType type){
    MyAutoBeanFactory beanFactory = AutoBeanFactorySource.create(MyAutoBeanFactory.class);
    MessageResponse response = new MessageResponse();
    response.setFrom(from);
    response.setMessage(body);
    response.setMessageType(type);
    AutoBean<IMessageResponse> bean = beanFactory.create(IMessageResponse.class, response);
    String json = AutoBeanCodex.encode(bean).getPayload();
    return json;
  }
 
}
TOP

Related Classes of com.changestuffs.server.utils.DtoToJson

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.