It would be great to have the whole api annotated with @Nullable and @NonNull.
Also it would play way better together with kotlin. For example the JsonAdapter.Factory:
/**
* Attempts to create an adapter for {@code type} annotated with {@code annotations}. This
* returns the adapter if one was created, or null if this factory isn't capable of creating
* such an adapter.
*
* <p>Implementations may use to {@link Moshi#adapter} to compose adapters of other types, or
* {@link Moshi#nextAdapter} to delegate to the underlying adapter of the same type.
*/
JsonAdapter<?> create(Type type, Set<? extends Annotation> annotations, Moshi moshi);
Currently one really has to read the documentation.
What kotlin does by default is:
override fun create(type: Type?, annotations: MutableSet<out Annotation>?, moshi: Moshi?): JsonAdapter<*>
where it should be
override fun create(type: Type, annotations: MutableSet<out Annotation>, moshi: Moshi): JsonAdapter<*>?
Maybe there should be one big issue on one project somewhere to communicate plans?
kind of tracking this here: https://github.com/square/retrofit/issues/624#issuecomment-265429436
Something else: Validation of null input is not done Properly. I just received a bit weird crash because I passed null to JsonAdapter.fromJson(String) and the Buffer called string.length() in writeUtf8 and caused a NPE. It would be handy if you could check the arguments and fail immediately rather than relying on the implementation to crash.
Implemented. https://github.com/square/moshi/pull/297
If I understand correctly the String is still not annotated and will crash in Okios Buffer?
Annotated or not, it's still crashing because a dependent is crashing.
If this is blocking you, please vote this up: https://youtrack.jetbrains.com/oauth?state=%2Fissue%2FKT-10942
package-info.java is annotated with @ParametersAreNonnullByDefault but Kotlin doesn't support that yet.
Should be fixed in Kotlin 1.1.4. Support for the annotations can be enabled by passing the -Xjsr305-annotations=enable command line option to the compiler. Info in the release announcement.
No further action for Moshi on this.