Skip to content
This repository has been archived by the owner on Dec 7, 2019. It is now read-only.

convert middleware jackson to kotlin #350

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apply from: 'buildsystem/dependencies.gradle'

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = '1.2.41'
ext.kotlin_version = '1.2.51'
repositories {
mavenLocal()
maven {
Expand All @@ -19,11 +19,11 @@ buildscript {
}

rootProject.ext.versions = [
kotlin: '1.2.21'
kotlin: '1.2.51'
]

dependencies {
classpath 'com.android.tools.build:gradle:3.2.0-alpha16'
classpath 'com.android.tools.build:gradle:3.2.0-beta02'
classpath 'com.google.gms:google-services:3.0.0'
classpath 'com.getkeepsafe.dexcount:dexcount-gradle-plugin:0.5.6'
classpath 'net.ltgt.gradle:gradle-errorprone-plugin:0.0.11'
Expand Down
3 changes: 2 additions & 1 deletion buildsystem/dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ ext.versions = [
okio : '1.13.0',
gson : '2.8.1',
moshi : '1.5.0',
jackson : '2.8.8',
jackson : '2.9.6',
guava : '19.0',
javapoet : '1.8.0',
immutables : '2.2.1',
Expand Down Expand Up @@ -96,6 +96,7 @@ ext.libraries = [
gson : "com.google.code.gson:gson:$versions.gson",
moshi : "com.squareup.moshi:moshi:$versions.moshi",
jacksonCore : "com.fasterxml.jackson.core:jackson-core:$versions.jackson",
jacksonKotlin : "com.fasterxml.jackson.module:jackson-module-kotlin:$versions.jackson",
jacksonDatabind : "com.fasterxml.jackson.core:jackson-databind:$versions.jackson",
guava : "com.google.guava:guava:$versions.guava",
javapoet : "com.squareup:javapoet:$versions.javapoet",
Expand Down
26 changes: 19 additions & 7 deletions middleware-jackson/build.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
plugins {
id 'org.jetbrains.kotlin.jvm'
}

apply plugin: 'java'

group = GROUP
Expand All @@ -8,20 +12,28 @@ dependencies {
implementation project(path: ':filesystem')
compileOnly libraries.jsr305
implementation libraries.jacksonCore
implementation libraries.jacksonKotlin
implementation libraries.jacksonDatabind
implementation libraries.okio
compileOnly libraries.javax
testImplementation libraries.mockito
testImplementation libraries.junit
}

buildscript {
tasks.withType(JavaCompile) {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we switch to implementation instead?

}

apply from: rootProject.file("gradle/maven-push.gradle")
apply from: rootProject.file("gradle/checkstyle.gradle")
apply from: rootProject.file("gradle/pmd.gradle")
repositories {
mavenCentral()
}
compileKotlin {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we switch to implementation here as well, please?

kotlinOptions {
jvmTarget = "1.8"
}
}
compileTestKotlin {
kotlinOptions {
jvmTarget = "1.8"
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.nytimes.android.external.store3.middleware.jackson

import com.fasterxml.jackson.core.JsonProcessingException
import com.fasterxml.jackson.databind.ObjectMapper
import com.nytimes.android.external.fs3.BufferedSourceAdapter

import java.io.ByteArrayInputStream
import javax.inject.Inject

import io.reactivex.exceptions.Exceptions
import okio.BufferedSource
import okio.Okio

/**
* An implementation of [BufferedSourceAdapter] that uses [ObjectMapper] to convert Java values to JSON.
*/
class JacksonBufferedSourceAdapter<Parsed> @Inject
constructor(private val objectMapper: ObjectMapper) : BufferedSourceAdapter<Parsed> {

override fun toJson(value: Parsed): BufferedSource {
try {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can lift that return statement before try :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, please

return Okio.buffer(Okio.source(ByteArrayInputStream(objectMapper.writeValueAsBytes(value))))
} catch (e: JsonProcessingException) {
throw Exceptions.propagate(e)
}

}
}

This file was deleted.

Loading