Search code examples
firebasekotlinfirebase-realtime-databasemicronaut

Firebase creating nested object on POST


I am trying to HTTP POST a Treasure to a Firebase Real Time Database(2) using Micronaut's RxHTTP (1).

data class Treasure
(
    val treasureId : String? = null,

    val name : String,

    val description: String,

    val amount : Double,

    val lat : Double,

    val lng : Double
)
@Client("\${treauser.trasures.url}")
interface TreasureRepository : CreateTreasurePort
{
    @Post("/Treasure.json")
    override fun add(treasure : Treasure)
}

It posts but for some reason it nesting the object under uuid.

enter image description here

I do not want treasure to be there, I just want all five properties under the UID.

1: docs.micronaut.io/latest/guide/httpClient.html#clientAnnotation 2: firebase.google.com/docs/reference/rest/database#section-post


Solution

  • Solved by adding the @Body1 annotation.

    @Client("\${treauser.trasures.url}")
    interface TreasureRepository : CreateTreasurePort
    {
        @Post("/Treasure.json")
        override fun add(@Body treasure : Treasure)
    }
    

    1: Body Annotation: https://docs.micronaut.io/latest/api/io/micronaut/http/annotation/Body.html