All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.mocean.modules.ResponseFactory Maven / Gradle / Ivy

Go to download

This is an Mocean SDK written in java. To use it you will need a mocean account. Signup for free at https://moceanapi.com

There is a newer version: 1.1.5
Show newest version
package com.mocean.modules;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.mocean.exception.MoceanErrorException;

import javax.xml.bind.JAXB;
import java.io.IOException;
import java.io.StringReader;

public class ResponseFactory {
    private ResponseFactory() {
    }

    public static  T createObjectFromRawResponse(String rawResponse, Class type) throws MoceanErrorException {
        //first check whether is json
        try {
            return new ObjectMapper().readValue(rawResponse, type);
        } catch (IOException e) {
            //format is not json, try xml now
            try {
                return JAXB.unmarshal(new StringReader(rawResponse), type);
            } catch (Exception ex) {
                throw new MoceanErrorException("unable to parse response, " + rawResponse);
            }
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy