Skip to content

Commit

Permalink
release 8.2.0 (#139)
Browse files Browse the repository at this point in the history
* feat: 🎸 new types JsBinary and JsInstant

* feat: 🎸 optics for new types binary and instant

* feat: 🎸 prism from base64 encoded string to byte[]

* ci: 🎡 set new version 8.2.0

* docs: ✏️ notice file update

* feat: 🎸 prism from string to instant

* fix: 🐛 equals for JsBinary and JsIntant

* bug toJsBinary and toJsIntant

* remove scala tests

* fix: 🐛 added binary generators and refactor type of date gen

* test: 💍 binary and instant tests for generators

* fix: 🐛 bug jsinstant and jsbinary parsers

* test: 💍 rename test classes

* docs: ✏️ added circle badge

* docs: ✏️ readme makeover

* docs: ✏️ changelog 8.2.0 version

* docs: ✏️ remove contributing section
  • Loading branch information
imrafaelmerino committed Jul 15, 2020
1 parent c4a7607 commit 1064ea6
Show file tree
Hide file tree
Showing 160 changed files with 20,781 additions and 5,155 deletions.
1,584 changes: 0 additions & 1,584 deletions .editorconfig

This file was deleted.

4 changes: 2 additions & 2 deletions NOTICE
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ The following NOTICEs are pertain to software distributed with this project.
// Version 2.4.0.0, in this case for
// ------------------------------------------------------------------

Some code from the library org.scala.lang:scala-library is packaged in json-values.
Some code from the library com.fasterxml.jackson.core:jackson-core is packaged in json-values.
Some code from the library DSL-JSON library (https://github.com/ngs-doo/dsl-json)
has been packaged and modified in json-values.

23 changes: 23 additions & 0 deletions benchmarking/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
<JACKSON-VERSION>2.11.1</JACKSON-VERSION>
<JSON-SCHEMA-VALIDATOR.VERSION>2.2.14</JSON-SCHEMA-VALIDATOR.VERSION>
<JUSTIFY.VERSION>2.1.0</JUSTIFY.VERSION>
<VALIDATION-API.VERSION>2.0.1.Final</VALIDATION-API.VERSION>
<HIBERNATE-VALIDATOR-ANNOTATION-PROCESSOR.VERSION>6.1.5.Final</HIBERNATE-VALIDATOR-ANNOTATION-PROCESSOR.VERSION>
<HIBERNATE-VALIDATOR.VERSION>6.0.2.Final</HIBERNATE-VALIDATOR.VERSION>
</properties>
<dependencies>
<dependency>
Expand All @@ -34,6 +37,26 @@
<artifactId>json-schema-validator</artifactId>
<version>${JSON-SCHEMA-VALIDATOR.VERSION}</version>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>${VALIDATION-API.VERSION}</version>
</dependency>
<dependency>
<groupId>org.hibernate.validator</groupId>
<artifactId>hibernate-validator</artifactId>
<version>${HIBERNATE-VALIDATOR.VERSION}</version>
</dependency>
<dependency>
<groupId>org.hibernate.validator</groupId>
<artifactId>hibernate-validator-annotation-processor</artifactId>
<version>${HIBERNATE-VALIDATOR.VERSION}</version>
</dependency>
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>javax.el</artifactId>
<version>3.0.1-b11</version>
</dependency>
<dependency>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-core</artifactId>
Expand Down
71 changes: 39 additions & 32 deletions benchmarking/src/main/java/jsonvalues/benchmark/Conf.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package jsonvalues.benchmark;

import jsonvalues.JsArray;
import jsonvalues.spec.JsObjSpec;
import jsonvalues.spec.JsSpecs;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
Expand All @@ -19,36 +18,38 @@ public class Conf
public static final String PERSON_JSON;
public static final String PERSON_jSON_SCHEMA;

public final static JsObjSpec PERSON_SPEC = JsObjSpec.strict("firstName",
str,
"lastName",
str,
"age",
integer(greaterOrEqualThan(0)),
"latitude",
decimal(interval(new BigDecimal(-90),
new BigDecimal(90)
)
),
"longitude",
decimal(interval(new BigDecimal(-180),
new BigDecimal(180)
)
),
"fruits",
arrayOfStr,
"numbers",
arrayOfInt,
"vegetables",
arrayOf(JsObjSpec.strict("veggieName",
str,
"veggieLike",
bool
)
)
);
public final static JsObjSpec PERSON_SPEC;

static {
Predicate<JsArray> greaterThanOne = a -> a.size() > 1;
PERSON_SPEC = JsObjSpec.strict("firstName",
str(length(1,255)),
"lastName",
str(length(1,255)),
"age",
integer(interval(0,110)),
"latitude",
decimal(interval(new BigDecimal(-90),
new BigDecimal(90)
)
),
"longitude",
decimal(interval(new BigDecimal(-180),
new BigDecimal(180)
)
),
"fruits",
arrayOfStrSuchThat(greaterThanOne),
"numbers",
arrayOfIntSuchThat(greaterThanOne),
"vegetables",
arrayOf(JsObjSpec.strict("veggieName",
str(length(1,255)),
"veggieLike",
bool
)
).optional()
);
PERSON_jSON_SCHEMA = fileContent("personSchema.json");
PERSON_JSON = fileContent("person.json");

Expand Down Expand Up @@ -77,13 +78,19 @@ private static String fromStream(InputStream in) throws IOException {
return out.toString();
}

private static IntPredicate greaterOrEqualThan(int value) {
return i -> i >= value;

private static IntPredicate interval(int min,int max) {
return i -> i >= min && i<=max;
}

private static Predicate<BigDecimal> interval(BigDecimal min,
BigDecimal max
) {
return v -> v.doubleValue() <= max.doubleValue() && v.doubleValue() >= min.doubleValue();
}

private static Predicate<String> length(int min,int max){
return s -> s.length()>= min && s.length()<=max;

}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,41 +1,115 @@
package jsonvalues.benchmark;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.networknt.schema.JsonSchema;
import com.networknt.schema.JsonSchemaFactory;
import com.github.fge.jackson.JsonLoader;
import com.github.fge.jsonschema.core.exceptions.ProcessingException;
import com.github.fge.jsonschema.core.load.Dereferencing;
import com.github.fge.jsonschema.core.load.configuration.LoadingConfiguration;
import com.github.fge.jsonschema.main.JsonSchema;
import com.github.fge.jsonschema.main.JsonSchemaFactory;
import jsonvalues.JsObj;
import jsonvalues.spec.JsObjParser;
import org.leadpony.justify.api.JsonValidationService;
import org.openjdk.jmh.annotations.*;
import org.openjdk.jmh.infra.Blackhole;

import javax.json.JsonObject;
import javax.json.JsonReader;
import javax.validation.ConstraintViolation;
import javax.validation.Validation;
import javax.validation.Validator;
import javax.validation.ValidatorFactory;
import java.io.IOException;
import java.util.Map;
import java.io.StringReader;
import java.util.Set;
import java.util.concurrent.TimeUnit;

import static jsonvalues.benchmark.Conf.PERSON_JSON;
import static jsonvalues.benchmark.Conf.PERSON_SPEC;
import static jsonvalues.benchmark.Conf.*;

@OutputTimeUnit(TimeUnit.SECONDS)
@BenchmarkMode(Mode.Throughput)
@State(Scope.Benchmark)
public class JsDeserializers {

private final static ObjectMapper objectMapper = new ObjectMapper();
// jackson mapper
private static final ObjectMapper objectMapper = new ObjectMapper();

// json-values parser
private static final JsObjParser jsonParser = new JsObjParser(PERSON_SPEC);

// hibernate validator init
private static final ValidatorFactory validatorFactory = Validation.buildDefaultValidatorFactory();
private static final Validator validator = validatorFactory.getValidator();

// justify init
private static final JsonValidationService serviceJustify = JsonValidationService.newInstance();
private static final org.leadpony.justify.api.JsonSchema schemaJustify =
serviceJustify.readSchema(new StringReader(PERSON_jSON_SCHEMA));

// json schema validator init
private static final LoadingConfiguration cfg = LoadingConfiguration.newBuilder()
.dereferencing(Dereferencing.INLINE)
.freeze();
private static final JsonSchemaFactory jsonSchemaFactory = JsonSchemaFactory.newBuilder()
.setLoadingConfiguration(cfg)
.freeze();
private static final JsonSchema schema;

static {
try {
schema = jsonSchemaFactory.getJsonSchema(JsonLoader.fromString(PERSON_jSON_SCHEMA));
} catch (Exception e) {
throw new RuntimeException(e);
}
}

private final static JsObjParser jsonParser = new JsObjParser(PERSON_SPEC);
@Benchmark
public void json_schema_validator(Blackhole bh) throws JsonProcessingException, ProcessingException {
JsonNode json = objectMapper.readTree(PERSON_JSON);
bh.consume(schema.validate(json));
}

@Benchmark
public void json_spec(Blackhole bh) {
bh.consume(jsonParser.parse(PERSON_JSON));
public void justify(Blackhole bh) {
JsonReader reader = serviceJustify.createReader(new StringReader(PERSON_JSON),
schemaJustify,
bh::consume
);
JsonObject json = reader.readObject();

reader.close();

bh.consume(json);
}

@Benchmark
public void jackson(Blackhole bh) throws IOException {
public void jackson_node(Blackhole bh) throws IOException {
bh.consume(objectMapper.readTree(PERSON_JSON));
}

@Benchmark
public void jackson_pojo(Blackhole bh) throws JsonProcessingException {
Person person = objectMapper.readValue(PERSON_JSON, Person.class);
bh.consume(person);
}

@Benchmark
public void jackson_pojo_bean_validation(Blackhole bh) throws JsonProcessingException {
PersonWithAnnotations person = objectMapper.readValue(PERSON_JSON, PersonWithAnnotations.class);
Set<ConstraintViolation<PersonWithAnnotations>> validate = validator.validate(person);
bh.consume(validate.size() == 0);
}

@Benchmark
public void json_values(Blackhole bh) {
bh.consume(JsObj.parse(PERSON_JSON));
}

@Benchmark
public void json_spec(Blackhole bh) {
bh.consume(jsonParser.parse(PERSON_JSON));
}

}

This file was deleted.

Loading

0 comments on commit 1064ea6

Please sign in to comment.