forked from openrs2/openrs2
parent
08afa71d30
commit
5aa92fd600
@ -0,0 +1,27 @@ |
||||
plugins { |
||||
`maven-publish` |
||||
kotlin("jvm") |
||||
} |
||||
|
||||
dependencies { |
||||
api("com.fasterxml.jackson.core:jackson-databind:${Versions.jackson}") |
||||
api("com.google.inject:guice:${Versions.guice}") |
||||
|
||||
implementation("com.fasterxml.jackson.module:jackson-module-kotlin:${Versions.jackson}") |
||||
} |
||||
|
||||
publishing { |
||||
publications.create<MavenPublication>("maven") { |
||||
from(components["java"]) |
||||
|
||||
pom { |
||||
packaging = "jar" |
||||
name.set("OpenRS2 JSON") |
||||
description.set( |
||||
""" |
||||
Guava module for creating a JSON ObjectMapper. |
||||
""".trimIndent() |
||||
) |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,8 @@ |
||||
package dev.openrs2.json |
||||
|
||||
import javax.inject.Qualifier |
||||
|
||||
@Qualifier |
||||
@Retention(AnnotationRetention.RUNTIME) |
||||
@Target(AnnotationTarget.FIELD, AnnotationTarget.VALUE_PARAMETER, AnnotationTarget.FUNCTION) |
||||
public annotation class Json |
@ -0,0 +1,18 @@ |
||||
package dev.openrs2.json |
||||
|
||||
import com.fasterxml.jackson.databind.Module |
||||
import com.fasterxml.jackson.databind.ObjectMapper |
||||
import com.google.inject.AbstractModule |
||||
import com.google.inject.Scopes |
||||
import com.google.inject.multibindings.Multibinder |
||||
|
||||
public object JsonModule : AbstractModule() { |
||||
override fun configure() { |
||||
Multibinder.newSetBinder(binder(), Module::class.java) |
||||
|
||||
bind(ObjectMapper::class.java) |
||||
.annotatedWith(Json::class.java) |
||||
.toProvider(ObjectMapperProvider::class.java) |
||||
.`in`(Scopes.SINGLETON) |
||||
} |
||||
} |
@ -0,0 +1,19 @@ |
||||
package dev.openrs2.json |
||||
|
||||
import com.fasterxml.jackson.databind.Module |
||||
import com.fasterxml.jackson.databind.ObjectMapper |
||||
import com.fasterxml.jackson.databind.PropertyNamingStrategy |
||||
import com.fasterxml.jackson.module.kotlin.registerKotlinModule |
||||
import javax.inject.Inject |
||||
import javax.inject.Provider |
||||
|
||||
public class ObjectMapperProvider @Inject constructor( |
||||
private val modules: Set<@JvmSuppressWildcards Module> |
||||
) : Provider<ObjectMapper> { |
||||
override fun get(): ObjectMapper { |
||||
return ObjectMapper() |
||||
.registerKotlinModule() |
||||
.registerModules(modules) |
||||
.setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE) |
||||
} |
||||
} |
@ -0,0 +1,8 @@ |
||||
package dev.openrs2.yaml |
||||
|
||||
import javax.inject.Qualifier |
||||
|
||||
@Qualifier |
||||
@Retention(AnnotationRetention.RUNTIME) |
||||
@Target(AnnotationTarget.FIELD, AnnotationTarget.VALUE_PARAMETER, AnnotationTarget.FUNCTION) |
||||
public annotation class Yaml |
Loading…
Reference in new issue