Thread
#feed
    tipsy

    tipsy

    4 years ago
    now would be a great time to submit feature requests and bug reports
    s

    suresh

    4 years ago
    I am trying 2.0 for an internal test application. Do you have any example that uses Moshi instead of jackson?
    tipsy

    tipsy

    4 years ago
    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:
    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

    4 years ago
    @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+
    $ 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)
    tipsy

    tipsy

    4 years ago
    happy you like it
    did you get this warning even without using the routeoverviewutil ?
    s

    suresh

    4 years ago
    Not at runtime. I think
    jdeps
    will analyze all the classes anyway.
    tipsy

    tipsy

    4 years ago
    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

    4 years ago
    2.0.0 RC1
    tipsy

    tipsy

    4 years ago
    great, happy to hear that it's stable
    s

    suresh

    4 years ago
    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
    @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
    @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);
        }
      }
    tipsy

    tipsy

    4 years ago
    @suresh please create an issue on the tracker and i'll have a look later