Coder Social home page Coder Social logo

47degrees / helios Goto Github PK

View Code? Open in Web Editor NEW
167.0 167.0 22.0 813 KB

A purely functional JSON library for Kotlin built on Λrrow

Home Page: https://47deg.github.io/helios

License: Apache License 2.0

Kotlin 98.76% Shell 1.24%
functional functional-programming json json-parser kotlin kotlin-dsl kotlin-library

helios's People

Contributors

47degdev avatar 47erbot avatar adrianrafo avatar andrzejressel avatar antoniomateogomez avatar calvellido avatar chedabob avatar chetkhatri avatar cotel avatar dependabot[bot] avatar fedefernandez avatar franciscodr avatar israelperezglez avatar jachenry avatar lenguyenthanh avatar maureenelsberry avatar nomisrev avatar octogonapus avatar pakoito avatar rachelcarmena avatar raulraja avatar theosotr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

helios's Issues

Add more benchmarks to documentation

After #50 was merged we will have the current Helios benchmarking.
We also want to add the Benchmarks comparing it with the other libraries (executeBenchmarks task will give us that) and upload it as part of the CI on the same way master_benchmark does.

Java time support

We need to add support for all the java time types like Instant and ZonedDateTime

Nullable type results in StackOverflowError

Hi,

We play with nullable types, eg: val a: String? inside our data class. However generated code as well as simple test snippet results in StackOverflowError:

    "Nullable String element" {
      val str: String? = "abc"

      val js: Json = NullableEncoderInstance<String>(String.encoder()).run {
        str.encode()
      }

      println(js)
    }

It looks like NullableEncoderInstance cannot see encode extension function of the enclosed encoder:

override fun A?.encode(): Json =
    this?.let { a -> encoderA().let { a.encode() } } ?: JsNull

Use master json benchmark

After #48 was merged we need to use the json benchmark and delete the saved master benchmarks.
Also as part of this ticket, we want to clone the repo from the master branch and execute its benchmarks as part of the ci.

Option cannot handle non-existing fields in decoder

When using Option following code is generated for decoder:

value["items"].fold({Either.Left(KeyNotFound("items"))}, { arrow.core.Option.Companion.decoder(ListDecoderInstance(kotlin.String.decoder())).run { decode(it) } }),

So when "items" are not in the JSON error is returned despite using Option (which should allow not only values with null, but also non existing values).

Sealed class support

The annotation processor generates invalid code for sealed classes.

This code:

@json
sealed class LinkType {
    object Rotary : LinkType()
    object Prismatic : LinkType()

    companion object
}

Generates this:

fun LinkType.toJson(): Json = JsObject(mapOf())

fun Json.Companion.toLinkType(value: Json): Either<DecodingError, LinkType> =
  Either.applicative<DecodingError>().map(
	
,  {  ->
  LinkType()
}).fix()



fun LinkType.Companion.encoder() = object : Encoder<LinkType> {
  override fun LinkType.encode(): Json = this.toJson()
}

fun LinkType.Companion.decoder() = object : Decoder<LinkType> {
  override fun decode(value: Json): Either<DecodingError, LinkType> =
    Json.toLinkType(value)
}

Apart from the issue with the call to map(), it's not possible to construct a LinkType because it is a sealed class.

java.lang.NoSuchMethodError while generating decoders

I'm hitting the following error while generating decoders

[kapt] An exception occurred: java.lang.NoSuchMethodError: helios.meta.compiler.json.JsonElement.getPairs()Ljava/util/List;

I'm using helios in androidTests with the following dependencies:

    androidTestImplementation "com.47deg:helios-core:0.2.0"
    kaptAndroidTest "com.47deg:helios-dsl-meta:0.2.0"
    androidTestImplementation "com.47deg:helios-integration-retrofit:0.2.0"
    kaptAndroidTest "com.47deg:helios-meta:0.2.0"
    androidTestImplementation "com.47deg:helios-optics:0.2.0"
    androidTestImplementation "com.47deg:helios-parser:0.2.0"

And the data class I'm trying to generate a decoder for is:

@Serializable
@JsonClass(generateAdapter = true)
@json
data class CodeGeneratedNetworkResponse(
    val users: List<NetworkUser>,
    val status: String? = null,
    @SerialName("is_real_json")
    @Json(name = "is_real_json")
    val isRealJson: Boolean = false
) {
    companion object
}

Improve JsNumber and JsDecimal models

Currently JsDecimal is just only used for BigInteger and BigDecimal and all the other types Int, Long ... extends from the Number interface.
If we use JsNumber for the Number interface we can reduce a lot of boilerplate without losing compatibility between them.

Add CI

We need to add a CI for the PRs and maybe also for releases

Avoid deploy on upload commits

We should avoid deploying on upload commits. All those commits are done by 47degdev so we can filter by this on the travis.yml

Sidebar menu nested options support

I tried to this on the sidebar.yml:

  - title: Integrations
    
    nested_options:

      - title: Retrofit
        url: /docs/integrations/retrofit/

but it didn't work. I looked into the Arrow repo and that should be fine. Any clue @calvellido?

Safely generate encoders for product type

Related to #13

There is a problem lied with the meta compiler. More specifically when generating encoders/decoders for product types that depend on other encoders/decoders such as List<String> or Option< List<String>>.

@json data class Friend(val _id: String, val tags: List<String>)
@json data class SpecialFriend(val _id: String, val errorOrTags: Option< List<String>>)

We need to investigate how to safely generate encoders for these product types.

Helios brand

We will create a brand + basic microsite template

Enum support

The @json annotation can only be used on data classes. I don't see why helios shouldn't support enum types as well. The enum value can be encoded as a String.

Upgrade to Arrow 0.8.0

Currently, we have Arrow 0.6.2

There are so many changes and package modification from that version so, be careful doing this

Typealias breaks generated code

A data class which contains a member which is a typealias causes the generated code to be invalid.

This code:

typealias Foo = Either<String, Int>

@json
data class DataClass1(
    val foo: Foo
) {
    companion object
}

Generates this:

fun DataClass1.toJson(): Json = JsObject(mapOf(
"foo" to com.octogonapus.heliosdemo.Foo.encoder().run { foo.encode() }
))

foo.encode() is an unresolved reference.

Changing the data class to:

@json
data class DataClass1(
    val foo: Either<String, Int>
) {
    companion object
}

Generates this, which compiles fine:

fun DataClass1.toJson(): Json = JsObject(mapOf(
"foo" to arrow.core.Either.Companion.encoder(kotlin.String.encoder(), kotlin.Int.encoder()).run { foo.encode() }
))

There is a sample project containing this code here https://github.com/Octogonapus/helios-demo/tree/typealias_issue (specifically on branch typealias_issue).

Use Arrow version 0.10.0

We have new Arrow version 0.10.0 now. So it's time to update Arrow.

I would love to work on that if you think that's okay.

Array encoders and decoders

There are no default encoder() and decoder() functions for array types (Array<T>, DoubleArray, etc.). It looks like these were not added because the array types do not have companion objects. I think helios should still have functions for them, though. For example, here is a DoubleArray decoder I threw together:

fun doubleArrayDecoder() = object : Decoder<DoubleArray> {
    override fun decode(value: Json): Either<DecodingError, DoubleArray> = binding {
        value.asJsArray()
            .toEither { ArrayDecodingError(value) }
            .bind()
            .value
            .map {
                it.asJsNumber()
                    .toEither { NumberDecodingError(it) }
                    .bind()
                    .decode(Double.decoder())
                    .bind()
            }
            .toDoubleArray()
    }
}

Helios documentation

We need to add documentation about helios and how to use it in order to create the proper microsite.

Must to include:

  • What's Helios and how to import it
  • How to use Helios
  • Benchmarks
  • References and samples

This doc is apart from the Readme issue (#9)

Add print with formatting

Currently, we only have the toJsonString() method to transform a Json to a String.
We can support some extra methods like noSpaces or spaces2 to print the Json with some formatting

Adds performance check to ci

We need to add a check ideally per PR in order to know if we are decreasing the benchmarks.

The easiest way could be a task to update the benchmark through the CI

Weird 'add' function

Currently the add function looks like this:
fun add(key: String, value: Json): JsObject = JsObject(hashMapOf(key to value))

It's a bit confusing. Is it intentional? Maybe as an of it would be clearer.

Documentation in README.md

I know this project is still in development and not usable yet, but it looks very attractive, especially for people coming from Scala and Circe, so why don't put some effort into creating some sort of documentation, at least in the README.md. I believe it would help attract more developers to use and contribute to it.

Add retrofit integration docs and sample

We need to add the Helios retrofit integration to the microsite documentation and also add a little example on the samples module (or in a new module under the same folder)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.