Search in sources :

Example 1 with CustomChild

use of com.kdubb.retrofitexamples.domain.CustomChild in project retrofit-examples by kdubb1337.

the class SimpleClient method main.

public static void main(String[] args) {
    // Build the Retrofit REST adaptor pointing to the URL specified
    RestAdapter restAdapter = new RestAdapter.Builder().setServer(API_URL).build();
    // Create an instance of our SimpleApi interface.
    SimpleApi simpleApi = restAdapter.create(SimpleApi.class);
    // Call each of the methods and output the results
    System.out.println("simpleApi.simpleGet()=<<" + simpleApi.simpleGet() + ">>");
    System.out.println("simpleApi.simplePost()=<<" + simpleApi.simplePost() + ">>");
    System.out.println("simpleApi.simpleDelete()=<<" + simpleApi.simpleDelete() + ">>");
    System.out.println("simpleApi.simplePut()=<<" + simpleApi.simplePut() + ">>");
    System.out.println("simpleApi.simpleHead()=<<" + simpleApi.simpleHead() + ">>");
    System.out.println("simpleApi.simpleBoolean()=<<" + simpleApi.simpleBoolean() + ">>");
    System.out.println("simpleApi.simpleInteger()=<<" + simpleApi.simpleInteger() + ">>");
    System.out.println("simpleApi.simpleCollection()=<<" + simpleApi.simpleCollection() + ">>");
    try {
        ObjectMapper mapper = new ObjectMapper();
        // We want to take a peek to see if all the fields are set correctly
        CustomObject custom = simpleApi.simpleCustom();
        System.out.println("simpleApi.simpleCustom()=<<" + custom + ">>");
        System.out.println("simpleApi.simpleCustom() as JSON=<<" + mapper.writeValueAsString(custom) + ">>");
        CustomChild child = simpleApi.simpleChild();
        System.out.println("simpleApi.simpleChild()=<<" + child + ">>");
        System.out.println("simpleApi.simpleChild() as JSON=<<" + mapper.writeValueAsString(child) + ">>");
    } catch (IOException e) {
        LOG.error("Failed to convert objects to JSON", e);
    }
}
Also used : CustomObject(com.kdubb.retrofitexamples.domain.CustomObject) SimpleApi(com.kdubb.retrofitexamples.api.SimpleApi) IOException(java.io.IOException) RestAdapter(retrofit.RestAdapter) CustomChild(com.kdubb.retrofitexamples.domain.CustomChild) ObjectMapper(org.codehaus.jackson.map.ObjectMapper)

Example 2 with CustomChild

use of com.kdubb.retrofitexamples.domain.CustomChild in project retrofit-examples by kdubb1337.

the class CustomFactory method buildCustomChild.

public CustomChild buildCustomChild() {
    CustomChild customChild = new CustomChild();
    customChild.setA("a string thing");
    customChild.setB(123456);
    customChild.setC(true);
    customChild.setD(1.23456);
    Collection<String> strings = new ArrayList<String>();
    for (int i = 1; i < 4; i++) strings.add("string #" + i);
    customChild.setE(strings);
    customChild.setChildOnly("Only the child has this field");
    return customChild;
}
Also used : ArrayList(java.util.ArrayList) CustomChild(com.kdubb.retrofitexamples.domain.CustomChild)

Aggregations

CustomChild (com.kdubb.retrofitexamples.domain.CustomChild)2 SimpleApi (com.kdubb.retrofitexamples.api.SimpleApi)1 CustomObject (com.kdubb.retrofitexamples.domain.CustomObject)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)1 RestAdapter (retrofit.RestAdapter)1