Giter Site home page Giter Site logo

soap's Introduction

Soap

Scala on Android Parcelable with circe

Circle CI codecov Maven License

Introduction

As of version 4.0.0, Soap is no more than a simple wrapper around circe (a Scala JSON library). It allows to easily read/write from/to Bundle, Intent and SharedPreference as long as the appropriate circe codecs are in scope.

In previous versions of Soap, the library provided its own codec generation framework. As I spent more and more time working with circe, I realised how superior its codec derivation is and that I will not be able to provide and maintain anything nearly as good. I therefore decided to migrate Soap to circe. It might not be the fastest or memory optimized way of solving inter-process-communication (IPC), but it does provide the greatest development experience.

Warning
You can only use Soap to read data, if it has also been written with Soap. Reading form external Bundles (e.g. from a Notification) does not work, because the format differs.

Installation

libraryDependencies += "io.taig.android" %% "soap" % "4.1.0"

Quickstart

import io.taig.android.soap.implicits._

import io.taig.android.soap.Bundle

val bundle = Bundle( 2 )
    .write( "foo", 42 )
    .write( "bar", "foobar" )

bunlde.read[Int]( "foo" )           // Some( 42 )
bunlde.read[String]( "bar" )        // Some( "foobar" )
bunlde.read[Int]( "bar" )           // None
bunlde.read[String]( "foobar" )     // None

import android.content.Intent

val intent = new Intent()
    .write( "foo", 42 )
    .write( "bar", "foobar" )

intent.read[Int]( "foo" )           // Some( 42 )

import android.preference.PreferenceManager

val preferences = PreferenceManager.getDefaultSharedPreferences( ??? )
    .write( "foo", 42 )
    .write( "bar", "foobar" )

preferences.read[Int]( "foo" )      // Some( 42 )

See the circe documentation to find out more about codec generation.

soap's People

Contributors

taig avatar

Stargazers

 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

soap's Issues

Support Try

Investigate and maybe implement the scala Try type, in case the parcelable writeException message is suitable for this purpose.

Print a warning when write- / readSerializable is used

Usually the Serialization methods are not desired. Since it's hard to tell what the macro is actually doing there should be a notice during compile time when these methods are used (except the type explicitly implements Serializable, though).

Codecs should be contravariant

sealed trait MyEnum
object MyEnum {
    case object MyValue extends MyEnum
}

// Does not compile / infers wrong codecs
myIntent.write( "my_enum", MyEnum.MyValue )

// Compiles fine
myIntent.write[MyEnum]( "my_enum", MyEnum.MyValue )

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.