Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release 3.0.0 #57

Merged
merged 7 commits into from
Feb 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions .chglog/CHANGELOG.tpl.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{{ range .Versions }}
<a name="{{ .Tag.Name }}"></a>
## {{ if .Tag.Previous }}[{{ .Tag.Name }}]({{ $.Info.RepositoryURL }}/compare/{{ .Tag.Previous.Name }}...{{ .Tag.Name }}){{ else }}{{ .Tag.Name }}{{ end }} ({{ datetime "2006-01-02" .Tag.Date }})

{{ range .CommitGroups -}}
### {{ .Title }}

{{ range .Commits -}}
* {{ .Subject }}
{{ end }}
{{ end -}}

{{- if .NoteGroups -}}
{{ range .NoteGroups -}}
### {{ .Title }}

{{ range .Notes }}
{{ .Body }}
{{ end }}
{{ end -}}
{{ end -}}
{{ end -}}
27 changes: 27 additions & 0 deletions .chglog/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
style: github
template: CHANGELOG.tpl.md
info:
title: CHANGELOG
repository_url: https://github.com/imrafaelmerino/json-scala-values
options:
commits:
# filters:
# Type:
# - feat
# - fix
# - perf
# - refactor
commit_groups:
# title_maps:
# feat: Features
# fix: Bug Fixes
# perf: Performance Improvements
# refactor: Code Refactoring
header:
pattern: "^(\\w*)\\:\\s(.*)$"
pattern_maps:
- Type
- Subject
notes:
keywords:
- BREAKING CHANGE
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ deploy:
file:
- docs/README.md
- docs/index.md
name: Tom
- docs/CHANGELOG.md
name: Rufus
prerelease: false
provider: releases
skip_cleanup: false
Expand Down
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name := "json-scala-values"

version := "2.0.0"
version := "3.0.0"

scalaVersion := "2.13.0"

Expand Down
21 changes: 21 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<a name="v3.0.0"></a>
## [v3.0.0](https://github.com/imrafaelmerino/json-scala-values/releases/tag/v3.0.0) (2020-02-08)

### BREAKING CHANGE
* (spec) implicit conversions are moved from value.Preamble to value.spec.Preamble

* (spec) enum renamed to conts

* filter, filterKeys, map, mapKeys and reduce are renamed to filterAll, filterAllKeys, mapAll, mapAllKeys and reduceAll.

### Feat
* 🎸 JsObjFuture and JsArrayFuture
* 🎸 JsObjTry and JsArrayTry
* 🎸 filter, map and reduce that doesn't traverse the json recursively (they only iterate through the first level)
* 🎸 concat function to merge Json object and arrays. Arrays can be treated as sets, multisets or lists

### Fix

### Docs
* ✏️ improved documentation
* ✏️ added future and try in readme
100 changes: 82 additions & 18 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ In this case you need the dependency [json-scala-values-generator](https://githu

It requires Scala 2.13:

[![Maven](https://img.shields.io/maven-central/v/com.github.imrafaelmerino/json-scala-values_2.13/2.0.0)](https://search.maven.org/artifact/com.github.imrafaelmerino/json-scala-values_2.13/2.0.0/jar)
[![Maven](https://img.shields.io/maven-central/v/com.github.imrafaelmerino/json-scala-values_2.13/3.0.0)](https://search.maven.org/artifact/com.github.imrafaelmerino/json-scala-values_2.13/3.0.0/jar)

**libraryDependencies += "com.github.imrafaelmerino" %% "json-scala-values" % "2.0.0"**
**libraryDependencies += "com.github.imrafaelmerino" %% "json-scala-values" % "3.0.0"**

#### <a name="dotty"><a/> Dotty

[![Maven](https://img.shields.io/maven-central/v/com.github.imrafaelmerino/json-dotty-values_0.21/0.22.0-RC1)](https://search.maven.org/artifact/com.github.imrafaelmerino/json-dotty-values_0.21/0.22.0-RC1/jar)
[![Maven](https://img.shields.io/maven-central/v/com.github.imrafaelmerino/json-dotty-values_0.21/3.0.0)](https://search.maven.org/artifact/com.github.imrafaelmerino/json-dotty-values_0.21/3.0.0/jar)

**libraryDependencies += "com.github.imrafaelmerino" %% "json-dotty-values" % "0.22.0-RC1"**
**libraryDependencies += "com.github.imrafaelmerino" %% "json-dotty-values" % "3.0.0"**

## <a name="doc"><a/> Documentation
Go to the [project page](https://imrafaelmerino.github.io/json-scala-values/)
Expand All @@ -70,7 +70,6 @@ val person = JsObj("@type" -> "Person",
We can define a **spec** to validate the structure of the above Json:

```
//reuse this object
val personSpec = JsObjSpec("@type" -> "Person",
"age" -> int,
"name" -> str,
Expand All @@ -84,9 +83,7 @@ val personSpec = JsObjSpec("@type" -> "Person",
"books_id" -> arrayOfStr
)

//validate: JsObjSpec => Seq[Invalid]
person.validate(personSpec) == Seq.empty // no errors

```

A spec can be used to parse into a Json directly. This way, as soon as a parsed value doesn't satisfy
Expand All @@ -100,6 +97,73 @@ val bytes:Array[Byte] = ...
val b:Either[InvalidJson,JsObj] = personParser.parse(bytes)
```

Taming side effects with Future and Try monads:

```
val ageFuture:Future[Int] = ???

val latitudeFuture:Future[Double] = ???

val longitudeFuture:Future[Double] = ???

val addressFuture = JsObjFuture("location" -> JsArrayFuture(latitudeFuture,
longitudFuture
)
)

val future:Future[JsOb] = JsObjFuture("@type" -> "Person",
"age" -> ageFuture,
"name" -> "Rafael",
"gender" -> "MALE",
"address" -> addressFuture
)

```

```
val ageTry:Try[Int] = ???

val latitudeTry:Try[Double] = ???

val longitudeTry:Try[Double] = ???

val addressTry = JsObjTry("location" -> JsArrayTry(latitudeTry,
longitudTry
)
)

val tryObj:Try[JsOb] = JsObjTry("@type" -> "Person",
"age" -> ageTry,
"name" -> "Rafael",
"gender" -> "MALE",
"address" -> addressTry
)

```

You can even mix try and future:

```
val ageTry:Try[Int] = ???

val latitudeFuture:Future[Double] = ???

val longitudeTry:Try[Double] = ???

val addressFuture = JsObjFuture("location" -> JsArrayFuture(latitudeFuture,
longitudTry
)
)

val future:Future[JsOb] = JsObjFuture("@type" -> "Person",
"age" -> ageTry,
"name" -> "Rafael",
"gender" -> "MALE",
"address" -> addressFuture
)

```

Putting data in and getting data out:

```
Expand Down Expand Up @@ -127,23 +191,23 @@ y("a" / 0 / 0) == JsInt(0)
Manipulating Jsons with functions that traverses the whole structure recursively:

```
// map keys to lowercase
// map keys to lowercase traversing every element of the json

val toLowerCase:String=>String = _.toLowerCase

json mapKeys toLowerCase
json mapAllKeys toLowerCase

// trim string values. Not very functional impl. We'll see a better approach

val trimIfStr = (x: JsValue) => if (x.isStr) x.toJsStr.map(_.trim) else x
val trimIfStr = (x: JsPrimitive) => if (x.isStr) x.toJsStr.map(_.trim) else x

array map trimIfStr
array mapAll trimIfStr

// remove null values
// remove null values traversing every element of the json

val isNotNull:JsValue => Boolean = _.isNotNull
val isNotNull:JsPrimitive => Boolean = _.isNotNull

json filter isNotNull
json filterAll isNotNull

```

Expand All @@ -154,18 +218,18 @@ There are some optics defined in a different project [optics-json-values](https:
that makes data-manipulation more composable and concise. For example, the above example

```
val trimIfStr = (x: JsValue) => if (x.isStr) x.toJsStr.map(_.trim) else x
val trimIfStr = (x: JsPrimitive) => if (x.isStr) x.toJsStr.map(_.trim) else x

obj map trimIfStr
obj mapAll trimIfStr
```

could had been written using a Prism:
could have been written using a Prism:

```
import value.JsStrOptics.toJsStr
// monocle.Prism[JsValue,String]

obj map toJsStr.modify(_.trim)
obj mapAll toJsStr.modify(_.trim)
```

which is more functional.
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/dslplatform/json/MyNumberConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ private static BigDecimal parseNumberGeneric(final char[] buf,
}
}

private static class NumberInfo
static class NumberInfo
{
final char[] buffer;
final int length;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import value.JsNull$;
import value.JsValue;
import value.spec.Result;
import value.spec.Valid;
import value.spec.Valid$;

import java.io.IOException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.dslplatform.json.JsonReader;
import com.dslplatform.json.derializers.types.JsIntegralDeserializer;
import value.JsArray;
import value.JsArray$;
import value.JsNull$;
import value.JsValue;
import value.spec.Result;
Expand All @@ -12,7 +11,6 @@
import java.math.BigInteger;
import java.util.Objects;
import java.util.function.Function;
import java.util.function.IntFunction;

public final class JsArrayOfIntegralDeserializer extends JsArrayDeserializer
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@
import com.dslplatform.json.JsonReader;
import com.dslplatform.json.derializers.types.JsLongDeserializer;
import value.JsArray;
import value.JsArray$;
import value.JsNull$;
import value.JsValue;
import value.spec.Result;

import java.io.IOException;
import java.util.Objects;
import java.util.function.IntFunction;
import java.util.function.LongFunction;

public final class JsArrayOfLongDeserializer extends JsArrayDeserializer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import java.io.IOException;
import java.util.Objects;
import java.util.function.Function;
import java.util.function.IntFunction;

public final class JsArrayOfNumberDeserializer extends JsArrayDeserializer
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@
import com.dslplatform.json.derializers.types.JsTypeDeserializer;
import scala.collection.immutable.HashMap;
import scala.collection.immutable.Map;
import value.JsNull$;
import value.JsObj;
import value.JsValue;
import value.spec.Result;

import java.io.IOException;
import java.util.function.Function;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.dslplatform.json.JsonReader;
import com.dslplatform.json.MyNumberConverter;
import value.*;
import value.spec.Invalid;
import value.spec.Result;
import value.spec.Valid$;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import value.JsBigInt;
import value.JsNull$;
import value.JsValue;
import value.spec.Invalid;
import value.spec.Result;
import value.spec.Valid$;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.dslplatform.json.JsonReader;
import com.dslplatform.json.MyNumberConverter;
import value.*;
import value.spec.Invalid;
import value.spec.Result;
import value.spec.Valid$;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public void write(final JsonWriter sw,
final int size = value.size();
if (size > 0)
{
final Iterator<Tuple2<String, JsValue>> iterator = value.map()
final Iterator<Tuple2<String, JsValue>> iterator = value.bindings()
.iterator();
Tuple2<String, JsValue> kv = iterator.next();
sw.writeString(kv._1);
Expand Down
Loading