https://kotlinlang.org logo
#feed
Title
# feed
t

tipsy

06/30/2018, 1:04 PM
now would be a great time to submit feature requests and bug reports
s

suresh

07/08/2018, 3:54 AM
I am trying 2.0 for an internal test application. Do you have any example that uses Moshi instead of jackson?
t

tipsy

07/08/2018, 9:01 AM
i don't have an example of moshi in particular, but i can show you one for gson
you need to overwrite
fromJsonMapper
and `toJsonMapper`:
Copy code
JavalinJson.fromJsonMapper = object : FromJsonMapper {
    override fun <T> map(json: String, targetClass: Class<T>) = gson.fromJson(json, targetClass)
}

JavalinJson.toJsonMapper = object : ToJsonMapper {
    override fun map(obj: Any): String = gson.toJson(obj)
}
so for moshi you would just have to replace the right side of the equals sign,
gson.fromJson(json, targetClass)
and
gson.toJson(obj)
s

suresh

07/08/2018, 9:33 PM
@tipsy Got it.. liking this framework. Really surprised to see everything (like http(s), http/2 , websockets + jdk 10) working as expected just following the docs. Thanks for the awesome work.
One small issue was with the module path on JDK 9+
Copy code
$ jdeps --jdk-internals target/sample-app-1.0-SNAPSHOT-uber.jar
Warning: split package: sun.security.ssl jrt:/java.base target/sample-app-1.0-SNAPSHOT-uber.jar
sample-app-1.0-SNAPSHOT-uber.jar -> JDK removed internal API
sample-app-1.0-SNAPSHOT-uber.jar -> java.base
   io.javalin.core.util.RouteOverviewUtilKt           -> sun.reflect.ConstantPool                           JDK internal API (JDK removed internal API)
   org.conscrypt.Platform                             -> sun.security.x509.AlgorithmId                      JDK internal API (java.base)
   sun.security.ssl.ServerHandshaker                  -> sun.security.action.GetPropertyAction              JDK internal API (java.base)
   sun.security.ssl.ServerHandshaker                  -> sun.security.util.AlgorithmDecomposer              JDK internal API (java.base)
   sun.security.ssl.ServerHandshaker                  -> sun.security.util.KeyUtil                          JDK internal API (java.base)
   sun.security.ssl.ServerHandshaker                  -> sun.security.util.LegacyAlgorithmConstraints       JDK internal API (java.base)
t

tipsy

07/08/2018, 9:48 PM
happy you like it
did you get this warning even without using the routeoverviewutil ?
s

suresh

07/08/2018, 9:50 PM
Not at runtime. I think
jdeps
will analyze all the classes anyway.
t

tipsy

07/08/2018, 10:10 PM
alright
need to figure out what to do with that class 😬
btw @suresh, are you using 1.7.0 or 2.0.0 ?
s

suresh

07/08/2018, 11:38 PM
2.0.0 RC1
t

tipsy

07/08/2018, 11:52 PM
great, happy to hear that it's stable
s

suresh

08/27/2018, 4:03 AM
Would be great if you can also add a custom json adapter example using Moshi
i couldn’t make it work fully as Moshi adapters requires class/type for toJson and FromJson methods
Copy code
@NotNull
  @Override
  public String map(Object obj) {
    Type type = obj.getClass();
    JsonAdapter<Object> adapter = moshi().adapter(type);
    return adapter.toJson(obj);
  }
without proper type info, i have to do something like
Copy code
@NotNull
  @Override
  public String map(Object obj) {
    Class<?> clazz = obj.getClass();
    if (Res.class.isAssignableFrom(clazz)) {
      return moshi().adapter(Res.class).nullSafe().toJson((Res) obj);
    } else {
      return moshi().adapter(Object.class).toJson(obj);
    }
  }
t

tipsy

08/27/2018, 7:49 AM
@suresh please create an issue on the tracker and i'll have a look later
7 Views