Example usage for com.google.gson GsonBuilder setPrettyPrinting

List of usage examples for com.google.gson GsonBuilder setPrettyPrinting

Introduction

In this page you can find the example usage for com.google.gson GsonBuilder setPrettyPrinting.

Prototype

public GsonBuilder setPrettyPrinting() 

Source Link

Document

Configures Gson to output Json that fits in a page for pretty printing.

Usage

From source file:org.megam.deccanplato.provider.salesforce.crm.handler.EventImpl.java

License:Open Source License

/**
 * this method creates an event in salesforce.com and returns that event id.
 * This method gets input from a MAP(contains json data) and returns a MAp.
 * @param outMap /*from   www . ja v  a  2 s .com*/
 */
private Map<String, String> create() {

    final String SALESFORCE_CREATE_EVENT_URL = args.get(INSTANCE_URL) + SALESFORCE_EVENT_URL;
    Map<String, String> outMap = new HashMap<>();
    Map<String, String> header = new HashMap<String, String>();
    header.put(S_AUTHORIZATION, S_OAUTH + args.get(ACCESS_TOKEN));
    Map<String, Object> userAttrMap = new HashMap<String, Object>();
    userAttrMap.put(S_SUBJECT, args.get(SUBJECT));
    userAttrMap.put(S_STARTDATETIME, datetime.parse(args.get(START_DATE)));
    userAttrMap.put(S_ENDDATETIME, datetime.parse(args.get(END_DATE)));

    GsonBuilder gson = new GsonBuilder();
    gson.registerTypeAdapter(DateTime.class, new DateTimeTypeConverter());
    Gson obj = gson.setPrettyPrinting().create();
    TransportTools tst = new TransportTools(SALESFORCE_CREATE_EVENT_URL, null, header);
    tst.setContentType(ContentType.APPLICATION_JSON, obj.toJson(userAttrMap));
    TransportResponse response = null;
    try {
        String responseBody = TransportMachinery.post(tst).entityToString();
        outMap.put(OUTPUT, responseBody);

    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return outMap;
}

From source file:org.megam.deccanplato.provider.salesforce.crm.handler.OpportunitiesImpl.java

License:Open Source License

/**
 * this method creates an opportunity in salesforce.com and returns that opportunity id.
 * This method gets input from a MAP(contains json data) and returns a MAp.
 * @param outMap // w  w  w . j  a v a2  s . co m
 */
private Map<String, String> create() {
    final String SALESFORCE_CREATE_OPPORTUNITY_URL = args.get(INSTANCE_URL) + SALESFORCE_OPPORTUNITY_URL;
    Map<String, String> outMap = new HashMap<>();
    Map<String, String> header = new HashMap<String, String>();
    header.put(S_AUTHORIZATION, S_OAUTH + args.get(ACCESS_TOKEN));
    Map<String, Object> userAttrMap = new HashMap<String, Object>();
    userAttrMap.put(S_NAME, args.get(NAME));
    userAttrMap.put(S_STAGENAME, args.get(STAGE_NAME));
    userAttrMap.put(S_CLOSEDATE, DateTime.parse(args.get(CLOSE_DATE)));

    GsonBuilder gson = new GsonBuilder();
    gson.registerTypeAdapter(DateTime.class, new DateTimeTypeConverter());
    Gson obj = gson.setPrettyPrinting().create();
    TransportTools tst = new TransportTools(SALESFORCE_CREATE_OPPORTUNITY_URL, null, header);
    tst.setContentType(ContentType.APPLICATION_JSON, obj.toJson(userAttrMap));
    try {
        String responseBody = TransportMachinery.post(tst).entityToString();
        outMap.put(OUTPUT, responseBody);
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return outMap;
}

From source file:org.mobicents.servlet.restcomm.http.AccountsEndpoint.java

License:Open Source License

@PostConstruct
private void init() {
    final DaoManager storage = (DaoManager) context.getAttribute(DaoManager.class.getName());
    configuration = (Configuration) context.getAttribute(Configuration.class.getName());
    configuration = configuration.subset("runtime-settings");
    super.init(configuration);
    dao = storage.getAccountsDao();// ww w.  ja  v  a 2  s. c o m
    final AccountConverter converter = new AccountConverter(configuration);
    final GsonBuilder builder = new GsonBuilder();
    builder.registerTypeAdapter(Account.class, converter);
    builder.setPrettyPrinting();
    gson = builder.create();
    xstream = new XStream();
    xstream.alias("RestcommResponse", RestCommResponse.class);
    xstream.registerConverter(converter);
    xstream.registerConverter(new AccountListConverter(configuration));
    xstream.registerConverter(new RestCommResponseConverter(configuration));
}

From source file:org.mobicents.servlet.restcomm.http.ApplicationsEndpoint.java

License:Open Source License

@PostConstruct
public void init() {
    final DaoManager storage = (DaoManager) context.getAttribute(DaoManager.class.getName());
    dao = storage.getApplicationsDao();/*from  w ww. java  2s .c  o  m*/
    accountsDao = storage.getAccountsDao();
    configuration = (Configuration) context.getAttribute(Configuration.class.getName());
    configuration = configuration.subset("runtime-settings");
    super.init(configuration);
    final ApplicationConverter converter = new ApplicationConverter(configuration);
    final GsonBuilder builder = new GsonBuilder();
    builder.registerTypeAdapter(Application.class, converter);
    builder.setPrettyPrinting();
    gson = builder.create();
    xstream = new XStream();
    xstream.alias("RestcommResponse", RestCommResponse.class);
    xstream.registerConverter(converter);
    xstream.registerConverter(new ApplicationListConverter(configuration));
    xstream.registerConverter(new RestCommResponseConverter(configuration));
}

From source file:org.mobicents.servlet.restcomm.http.AvailablePhoneNumbersEndpoint.java

License:Open Source License

@PostConstruct
public void init() throws ObjectInstantiationException {
    configuration = (Configuration) context.getAttribute(Configuration.class.getName());
    daos = (DaoManager) context.getAttribute(DaoManager.class.getName());
    super.init(configuration.subset("runtime-settings"));

    phoneNumberProvisioningManager = (PhoneNumberProvisioningManager) context
            .getAttribute("PhoneNumberProvisioningManager");
    if (phoneNumberProvisioningManager == null) {
        final String phoneNumberProvisioningManagerClass = configuration
                .getString("phone-number-provisioning[@class]");
        Configuration phoneNumberProvisioningConfiguration = configuration.subset("phone-number-provisioning");
        Configuration telestaxProxyConfiguration = configuration.subset("runtime-settings")
                .subset("telestax-proxy");

        phoneNumberProvisioningManager = (PhoneNumberProvisioningManager) new ObjectFactory(
                getClass().getClassLoader()).getObjectInstance(phoneNumberProvisioningManagerClass);
        ContainerConfiguration containerConfiguration = new ContainerConfiguration(getOutboundInterfaces());
        phoneNumberProvisioningManager.init(phoneNumberProvisioningConfiguration, telestaxProxyConfiguration,
                containerConfiguration);
        context.setAttribute("phoneNumberProvisioningManager", phoneNumberProvisioningManager);
    }//  w  w  w  .  ja  v a 2  s . c om

    xstream = new XStream();
    xstream.alias("RestcommResponse", RestCommResponse.class);
    xstream.registerConverter(new AvailablePhoneNumberConverter(configuration));
    xstream.registerConverter(new AvailablePhoneNumberListConverter(configuration));
    xstream.registerConverter(new RestCommResponseConverter(configuration));
    final GsonBuilder builder = new GsonBuilder();
    builder.setPrettyPrinting();
    //        builder.serializeNulls();
    gson = builder.create();
}

From source file:org.mobicents.servlet.restcomm.http.ClientsEndpoint.java

License:Open Source License

@PostConstruct
public void init() {
    final DaoManager storage = (DaoManager) context.getAttribute(DaoManager.class.getName());
    dao = storage.getClientsDao();/*from   ww w .  j  a  v  a  2s  .  com*/
    accountsDao = storage.getAccountsDao();
    configuration = (Configuration) context.getAttribute(Configuration.class.getName());
    configuration = configuration.subset("runtime-settings");
    super.init(configuration);
    final ClientConverter converter = new ClientConverter(configuration);
    final GsonBuilder builder = new GsonBuilder();
    builder.registerTypeAdapter(Client.class, converter);
    builder.setPrettyPrinting();
    gson = builder.create();
    xstream = new XStream();
    xstream.alias("RestcommResponse", RestCommResponse.class);
    xstream.registerConverter(converter);
    xstream.registerConverter(new ClientListConverter(configuration));
    xstream.registerConverter(new RestCommResponseConverter(configuration));
}

From source file:org.mobicents.servlet.restcomm.http.IncomingPhoneNumbersEndpoint.java

License:Open Source License

@PostConstruct
public void init() throws ObjectInstantiationException {
    final DaoManager storage = (DaoManager) context.getAttribute(DaoManager.class.getName());
    configuration = (Configuration) context.getAttribute(Configuration.class.getName());
    super.init(configuration.subset("runtime-settings"));
    dao = storage.getIncomingPhoneNumbersDao();
    accountsDao = storage.getAccountsDao();

    phoneNumberProvisioningManager = (PhoneNumberProvisioningManager) context
            .getAttribute("PhoneNumberProvisioningManager");
    if (phoneNumberProvisioningManager == null) {
        final String phoneNumberProvisioningManagerClass = configuration
                .getString("phone-number-provisioning[@class]");
        Configuration phoneNumberProvisioningConfiguration = configuration.subset("phone-number-provisioning");
        Configuration telestaxProxyConfiguration = configuration.subset("runtime-settings")
                .subset("telestax-proxy");

        phoneNumberProvisioningManager = (PhoneNumberProvisioningManager) new ObjectFactory(
                getClass().getClassLoader()).getObjectInstance(phoneNumberProvisioningManagerClass);
        ContainerConfiguration containerConfiguration = new ContainerConfiguration(getOutboundInterfaces());
        phoneNumberProvisioningManager.init(phoneNumberProvisioningConfiguration, telestaxProxyConfiguration,
                containerConfiguration);
        context.setAttribute("phoneNumberProvisioningManager", phoneNumberProvisioningManager);
    }/*from  w  w w  .  ja v a 2 s  .c  om*/
    Configuration callbackUrlsConfiguration = configuration.subset("phone-number-provisioning")
            .subset("callback-urls");
    phoneNumberParameters = new PhoneNumberParameters(callbackUrlsConfiguration.getString("voice[@url]"),
            callbackUrlsConfiguration.getString("voice[@method]"), false,
            callbackUrlsConfiguration.getString("sms[@url]"),
            callbackUrlsConfiguration.getString("sms[@method]"),
            callbackUrlsConfiguration.getString("fax[@url]"),
            callbackUrlsConfiguration.getString("fax[@method]"),
            callbackUrlsConfiguration.getString("ussd[@url]"),
            callbackUrlsConfiguration.getString("ussd[@method]"));

    final IncomingPhoneNumberConverter converter = new IncomingPhoneNumberConverter(configuration);
    final GsonBuilder builder = new GsonBuilder();
    builder.serializeNulls();
    builder.registerTypeAdapter(IncomingPhoneNumber.class, converter);
    builder.setPrettyPrinting();
    gson = builder.create();
    xstream = new XStream();
    xstream.alias("RestcommResponse", RestCommResponse.class);
    xstream.registerConverter(converter);
    xstream.registerConverter(new IncomingPhoneNumberListConverter(configuration));
    xstream.registerConverter(new AvailableCountriesConverter(configuration));
    xstream.registerConverter(new RestCommResponseConverter(configuration));
}

From source file:org.mobicents.servlet.restcomm.http.NotificationsEndpoint.java

License:Open Source License

@PostConstruct
public void init() {
    final DaoManager storage = (DaoManager) context.getAttribute(DaoManager.class.getName());
    configuration = (Configuration) context.getAttribute(Configuration.class.getName());
    configuration = configuration.subset("runtime-settings");
    super.init(configuration);
    dao = storage.getNotificationsDao();
    accountsDao = storage.getAccountsDao();
    final NotificationConverter converter = new NotificationConverter(configuration);
    final GsonBuilder builder = new GsonBuilder();
    builder.registerTypeAdapter(Notification.class, converter);
    builder.setPrettyPrinting();
    gson = builder.create();/*from   w  ww . j av  a2 s  .co  m*/
    xstream = new XStream();
    xstream.alias("RestcommResponse", RestCommResponse.class);
    xstream.registerConverter(converter);
    xstream.registerConverter(new NotificationListConverter(configuration));
    xstream.registerConverter(new RestCommResponseConverter(configuration));
}

From source file:org.mobicents.servlet.restcomm.http.OutgoingCallerIdsEndpoint.java

License:Open Source License

@PostConstruct
public void init() {
    final DaoManager storage = (DaoManager) context.getAttribute(DaoManager.class.getName());
    configuration = (Configuration) context.getAttribute(Configuration.class.getName());
    configuration = configuration.subset("runtime-settings");
    super.init(configuration);
    dao = storage.getOutgoingCallerIdsDao();
    accountsDao = storage.getAccountsDao();
    final OutgoingCallerIdConverter converter = new OutgoingCallerIdConverter(configuration);
    final GsonBuilder builder = new GsonBuilder();
    builder.registerTypeAdapter(OutgoingCallerId.class, converter);
    builder.setPrettyPrinting();
    gson = builder.create();/*from w  w w.j  a v  a2s  .c om*/
    xstream = new XStream();
    xstream.alias("RestcommResponse", RestCommResponse.class);
    xstream.registerConverter(converter);
    xstream.registerConverter(new OutgoingCallerIdListConverter(configuration));
    xstream.registerConverter(new RestCommResponseConverter(configuration));
}

From source file:org.mobicents.servlet.restcomm.http.RecordingsEndpoint.java

License:Open Source License

@PostConstruct
public void init() {
    final DaoManager storage = (DaoManager) context.getAttribute(DaoManager.class.getName());
    configuration = (Configuration) context.getAttribute(Configuration.class.getName());
    configuration = configuration.subset("runtime-settings");
    super.init(configuration);
    dao = storage.getRecordingsDao();// w w w.j a va 2  s. co m
    accountsDao = storage.getAccountsDao();
    final RecordingConverter converter = new RecordingConverter(configuration);
    final GsonBuilder builder = new GsonBuilder();
    builder.registerTypeAdapter(Recording.class, converter);
    builder.setPrettyPrinting();
    gson = builder.create();
    xstream = new XStream();
    xstream.alias("RestcommResponse", RestCommResponse.class);
    xstream.registerConverter(converter);
    xstream.registerConverter(new RecordingListConverter(configuration));
    xstream.registerConverter(new RestCommResponseConverter(configuration));
}