All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.onyx.serialization.CustomAnnotationInspector.kt Maven / Gradle / Ivy

Go to download

Onyx Database is a graph database that is written in Kotlin and supports Java and Android. It is designed to be lightweight and easy to use. Features include in memory database, embedded, and remote server. It leverages its own ORM and storage.

The newest version!
package com.onyx.serialization

import com.fasterxml.jackson.annotation.ObjectIdGenerators
import com.fasterxml.jackson.databind.PropertyName
import com.fasterxml.jackson.databind.introspect.Annotated
import com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector
import com.fasterxml.jackson.databind.introspect.ObjectIdInfo
import com.onyx.buffer.BufferStreamable

/**
 * Created by Tim Osborn on 2/14/17.
 *
 * The purpose of this is because Jackson JSon serialization is a piece of shit.  I need to account for
 * nested objects.  Luckily they have an obscure hack for this.  That hack is below:
 */
class CustomAnnotationInspector : JacksonAnnotationIntrospector() {

    /**
     * If the object is an ObjectSerializable, than apply the hack.
     * @param annotated Object to see if hack applies
     * @return Object ID Info with annotation including @ID
     */
    override fun findObjectIdInfo(annotated: Annotated?): ObjectIdInfo? = if (BufferStreamable::class.java.isAssignableFrom(annotated!!.rawType)) {
        ObjectIdInfo(
                PropertyName.construct("@id",
                        null), null,
                ObjectIdGenerators.IntSequenceGenerator::class.java, null)
    } else super.findObjectIdInfo(annotated)
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy