Kong / unirest-java

Unirest in Java: Simplified, lightweight HTTP client library.
http://kong.github.io/unirest-java/
MIT License
2.59k stars 593 forks source link

get a Minimum unirest-java #359

Closed yunkaiOr2 closed 4 years ago

yunkaiOr2 commented 4 years ago

i want to remove dependency get a minimum library

com.konghq unirest-java 3.8.00 com.google.code.gson gson org.apache.httpcomponents httpasyncclient

when i exclude gson replace my custom json lib(like jackson, fastjson....) i get err

java.lang.NoClassDefFoundError: com/google/gson/Gson

now the library default and Strong binding gson

feature:

  1. support interface for ObjectMapper?
  2. support asObject(Type responseType)?

public interface ObjectMapper {

T readValue(String value, Class valueType); //replace readValue(String value, GenericType genericType) T readValue(String value, Type valueType); //default T readValue(String value, GenericType genericType){ // throw new UnirestException("Please implement me"); //} String writeValue(Object value); }
ryber commented 4 years ago

You have to implement an alternative ObjectMapper and add it to the configuration in order to use a different JSON implementation, I'll look into being able to exclude it although some things (like .asJson) is it's own implementation that leverages GSON and cannot be replaced. So excluding gson will break that

ryber commented 4 years ago

I've made the default object mapper lazy in 3.8.06, but you will still need gson on the path in order to work with the asJson methods as they do not use any other implementation