retVal = StreamSupport.stream(iterableKeys.spliterator(), true)
+ .map(formData::get)
+ .filter(formValues -> formValues.peekFirst().isFileItem())
+ .flatMap(Collection::stream)
+ .map(UndertowUpload::new)
+ .collect(Collectors.toList());
+
+ return Collections.unmodifiableList(retVal);
+ }
+
@Override
public InputStream in() {
blocking.get();
@@ -410,25 +420,22 @@ private FormData parseForm() {
try {
String tmpdir = conf.getString("application.tmpdir");
String charset = conf.getString("application.charset");
- String value = exchange.getRequestHeaders().getFirst("Content-Type");
- if (value != null) {
- MediaType type = MediaType.valueOf(value);
- if (MediaType.form.name().equals(type.name())) {
- blocking.get();
- form = new FormEncodedDataDefinition()
- .setDefaultEncoding(charset)
- .create(exchange)
- .parseBlocking();
- } else if (MediaType.multipart.name().equals(type.name())) {
- blocking.get();
- form = new MultiPartParserDefinition()
+
+ FormEncodedDataDefinition encodedParser = new FormEncodedDataDefinition().setDefaultEncoding(charset);
+ MultiPartParserDefinition multiPartParser = new MultiPartParserDefinition()
.setTempFileLocation(new File(tmpdir).toPath())
- .setDefaultEncoding(charset)
- .create(exchange)
- .parseBlocking();
- }
- }
- } catch (IOException x) {
+ .setDefaultEncoding(charset);
+ blocking.get();
+ FormDataParser parser = FormParserFactory
+ .builder(false)
+ .addParser(encodedParser)
+ .addParser(multiPartParser)
+ .build()
+ .createParser(exchange);
+
+ form = parser != null ? parser.parseBlocking() : NO_FORM;
+ } catch (IOException iox) {
+ throw new IllegalArgumentException("Bad Request...", iox);
}
}
return form;
diff --git a/modules/jooby-undertow/src/main/java/org/jooby/internal/undertow/UndertowResponse.java b/modules/jooby-undertow/src/main/java/org/jooby/internal/undertow/UndertowResponse.java
index 81ee01cbc1..7a1d60bf05 100644
--- a/modules/jooby-undertow/src/main/java/org/jooby/internal/undertow/UndertowResponse.java
+++ b/modules/jooby-undertow/src/main/java/org/jooby/internal/undertow/UndertowResponse.java
@@ -268,7 +268,8 @@ public void send(final byte[] bytes) throws Exception {
@Override
public void send(final ByteBuffer buffer) throws Exception {
- exchange.getResponseSender().send(buffer);
+ endExchange = false;
+ exchange.getResponseSender().send(buffer, new LogIoCallback(IoCallback.END_EXCHANGE));
}
@Override
diff --git a/modules/jooby-whoops/README.md b/modules/jooby-whoops/README.md
index 9f05af05ca..69ca0eef4a 100644
--- a/modules/jooby-whoops/README.md
+++ b/modules/jooby-whoops/README.md
@@ -1,5 +1,5 @@
-[](https://maven-badges.herokuapp.com/maven-central/org.jooby/jooby-whoops)
-[](https://javadoc.io/doc/org.jooby/jooby-whoops/1.5.0)
+[](http://mvnrepository.com/artifact/org.jooby/jooby-whoops/1.6.6)
+[](https://javadoc.io/doc/org.jooby/jooby-whoops/1.6.6)
[](http://jooby.org/doc/whoops)
# whoops
@@ -15,7 +15,7 @@ Pretty error page that helps you debug your web application.
org.jooby
jooby-whoops
- 1.5.0
+ 1.6.6
```
diff --git a/modules/jooby-whoops/pom.xml b/modules/jooby-whoops/pom.xml
index ee659ecb8b..94507ea4cf 100644
--- a/modules/jooby-whoops/pom.xml
+++ b/modules/jooby-whoops/pom.xml
@@ -5,7 +5,7 @@
org.jooby
modules
- 1.5.1-SNAPSHOT
+ 1.6.9
4.0.0
diff --git a/modules/jooby-yasson/README.md b/modules/jooby-yasson/README.md
new file mode 100644
index 0000000000..41cc52faf4
--- /dev/null
+++ b/modules/jooby-yasson/README.md
@@ -0,0 +1,60 @@
+[](http://mvnrepository.com/artifact/org.jooby/jooby-yasson/1.6.6)
+[](https://javadoc.io/doc/org.jooby/jooby-yasson/1.6.6)
+[](http://jooby.org/doc/yasson)
+# yasson
+
+JSON support via [yasson](https://github.com/eclipse-ee4j/yasson) library.
+
+## exports
+
+* [json-b](http://json-b.net/users-guide.html)
+* [Parser](/apidocs/org/jooby/Parser.html)
+* [Renderer](/apidocs/org/jooby/Renderer.html)
+
+## dependency
+
+```xml
+
+ org.jooby
+ jooby-yasson
+ 1.6.6
+
+```
+
+## usage
+
+```java
+import org.jooby.json.Yasson;
+
+{
+ use(new Yasson());
+
+ // sending
+ get("/my-api", req -> new MyObject());
+
+ // receiving a json body
+ post("/my-api", req -> {
+ MyObject obj = req.body(MyObject.class);
+ return obj;
+ });
+
+ // direct access to Jsonb
+ get("/access", req -> {
+ Jsonb jsonb = require(Jsonb.class);
+ // ...
+ });
+}
+```
+
+### configuration
+
+If you need a special setting or configuration for your [json-b](http://json-b.net/users-guide.html):
+
+```java
+{
+ use(new Yasson().doWith(builder -> {
+ builder.withFormatting(true);
+ // ...
+ });
+}
+```
diff --git a/modules/jooby-yasson/pom.xml b/modules/jooby-yasson/pom.xml
new file mode 100644
index 0000000000..4c3eafe522
--- /dev/null
+++ b/modules/jooby-yasson/pom.xml
@@ -0,0 +1,94 @@
+
+
+
+
+ org.jooby
+ modules
+ 1.6.9
+
+
+ 4.0.0
+ jooby-yasson
+
+ yasson module
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-surefire-plugin
+
+
+ **/*Test.java
+ **/*Feature.java
+ **/Issue*.java
+
+
+
+
+
+
+
+
+
+
+ org.jooby
+ jooby
+ ${project.version}
+
+
+
+
+ org.eclipse
+ yasson
+
+
+
+ org.glassfish
+ javax.json
+
+
+
+
+ org.jooby
+ jooby
+ ${project.version}
+ test
+ tests
+
+
+
+ junit
+ junit
+ test
+
+
+
+ org.easymock
+ easymock
+ test
+
+
+
+ org.powermock
+ powermock-api-easymock
+ test
+
+
+
+ org.powermock
+ powermock-module-junit4
+ test
+
+
+
+ org.jacoco
+ org.jacoco.agent
+ runtime
+ test
+
+
+
+
\ No newline at end of file
diff --git a/modules/jooby-yasson/src/main/java/org/jooby/json/Yasson.java b/modules/jooby-yasson/src/main/java/org/jooby/json/Yasson.java
new file mode 100644
index 0000000000..652df9c408
--- /dev/null
+++ b/modules/jooby-yasson/src/main/java/org/jooby/json/Yasson.java
@@ -0,0 +1,380 @@
+/**
+ * Apache License
+ * Version 2.0, January 2004
+ * http://www.apache.org/licenses/
+ *
+ * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+ *
+ * 1. Definitions.
+ *
+ * "License" shall mean the terms and conditions for use, reproduction,
+ * and distribution as defined by Sections 1 through 9 of this document.
+ *
+ * "Licensor" shall mean the copyright owner or entity authorized by
+ * the copyright owner that is granting the License.
+ *
+ * "Legal Entity" shall mean the union of the acting entity and all
+ * other entities that control, are controlled by, or are under common
+ * control with that entity. For the purposes of this definition,
+ * "control" means (i) the power, direct or indirect, to cause the
+ * direction or management of such entity, whether by contract or
+ * otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ * outstanding shares, or (iii) beneficial ownership of such entity.
+ *
+ * "You" (or "Your") shall mean an individual or Legal Entity
+ * exercising permissions granted by this License.
+ *
+ * "Source" form shall mean the preferred form for making modifications,
+ * including but not limited to software source code, documentation
+ * source, and configuration files.
+ *
+ * "Object" form shall mean any form resulting from mechanical
+ * transformation or translation of a Source form, including but
+ * not limited to compiled object code, generated documentation,
+ * and conversions to other media types.
+ *
+ * "Work" shall mean the work of authorship, whether in Source or
+ * Object form, made available under the License, as indicated by a
+ * copyright notice that is included in or attached to the work
+ * (an example is provided in the Appendix below).
+ *
+ * "Derivative Works" shall mean any work, whether in Source or Object
+ * form, that is based on (or derived from) the Work and for which the
+ * editorial revisions, annotations, elaborations, or other modifications
+ * represent, as a whole, an original work of authorship. For the purposes
+ * of this License, Derivative Works shall not include works that remain
+ * separable from, or merely link (or bind by name) to the interfaces of,
+ * the Work and Derivative Works thereof.
+ *
+ * "Contribution" shall mean any work of authorship, including
+ * the original version of the Work and any modifications or additions
+ * to that Work or Derivative Works thereof, that is intentionally
+ * submitted to Licensor for inclusion in the Work by the copyright owner
+ * or by an individual or Legal Entity authorized to submit on behalf of
+ * the copyright owner. For the purposes of this definition, "submitted"
+ * means any form of electronic, verbal, or written communication sent
+ * to the Licensor or its representatives, including but not limited to
+ * communication on electronic mailing lists, source code control systems,
+ * and issue tracking systems that are managed by, or on behalf of, the
+ * Licensor for the purpose of discussing and improving the Work, but
+ * excluding communication that is conspicuously marked or otherwise
+ * designated in writing by the copyright owner as "Not a Contribution."
+ *
+ * "Contributor" shall mean Licensor and any individual or Legal Entity
+ * on behalf of whom a Contribution has been received by Licensor and
+ * subsequently incorporated within the Work.
+ *
+ * 2. Grant of Copyright License. Subject to the terms and conditions of
+ * this License, each Contributor hereby grants to You a perpetual,
+ * worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ * copyright license to reproduce, prepare Derivative Works of,
+ * publicly display, publicly perform, sublicense, and distribute the
+ * Work and such Derivative Works in Source or Object form.
+ *
+ * 3. Grant of Patent License. Subject to the terms and conditions of
+ * this License, each Contributor hereby grants to You a perpetual,
+ * worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ * (except as stated in this section) patent license to make, have made,
+ * use, offer to sell, sell, import, and otherwise transfer the Work,
+ * where such license applies only to those patent claims licensable
+ * by such Contributor that are necessarily infringed by their
+ * Contribution(s) alone or by combination of their Contribution(s)
+ * with the Work to which such Contribution(s) was submitted. If You
+ * institute patent litigation against any entity (including a
+ * cross-claim or counterclaim in a lawsuit) alleging that the Work
+ * or a Contribution incorporated within the Work constitutes direct
+ * or contributory patent infringement, then any patent licenses
+ * granted to You under this License for that Work shall terminate
+ * as of the date such litigation is filed.
+ *
+ * 4. Redistribution. You may reproduce and distribute copies of the
+ * Work or Derivative Works thereof in any medium, with or without
+ * modifications, and in Source or Object form, provided that You
+ * meet the following conditions:
+ *
+ * (a) You must give any other recipients of the Work or
+ * Derivative Works a copy of this License; and
+ *
+ * (b) You must cause any modified files to carry prominent notices
+ * stating that You changed the files; and
+ *
+ * (c) You must retain, in the Source form of any Derivative Works
+ * that You distribute, all copyright, patent, trademark, and
+ * attribution notices from the Source form of the Work,
+ * excluding those notices that do not pertain to any part of
+ * the Derivative Works; and
+ *
+ * (d) If the Work includes a "NOTICE" text file as part of its
+ * distribution, then any Derivative Works that You distribute must
+ * include a readable copy of the attribution notices contained
+ * within such NOTICE file, excluding those notices that do not
+ * pertain to any part of the Derivative Works, in at least one
+ * of the following places: within a NOTICE text file distributed
+ * as part of the Derivative Works; within the Source form or
+ * documentation, if provided along with the Derivative Works; or,
+ * within a display generated by the Derivative Works, if and
+ * wherever such third-party notices normally appear. The contents
+ * of the NOTICE file are for informational purposes only and
+ * do not modify the License. You may add Your own attribution
+ * notices within Derivative Works that You distribute, alongside
+ * or as an addendum to the NOTICE text from the Work, provided
+ * that such additional attribution notices cannot be construed
+ * as modifying the License.
+ *
+ * You may add Your own copyright statement to Your modifications and
+ * may provide additional or different license terms and conditions
+ * for use, reproduction, or distribution of Your modifications, or
+ * for any such Derivative Works as a whole, provided Your use,
+ * reproduction, and distribution of the Work otherwise complies with
+ * the conditions stated in this License.
+ *
+ * 5. Submission of Contributions. Unless You explicitly state otherwise,
+ * any Contribution intentionally submitted for inclusion in the Work
+ * by You to the Licensor shall be under the terms and conditions of
+ * this License, without any additional terms or conditions.
+ * Notwithstanding the above, nothing herein shall supersede or modify
+ * the terms of any separate license agreement you may have executed
+ * with Licensor regarding such Contributions.
+ *
+ * 6. Trademarks. This License does not grant permission to use the trade
+ * names, trademarks, service marks, or product names of the Licensor,
+ * except as required for reasonable and customary use in describing the
+ * origin of the Work and reproducing the content of the NOTICE file.
+ *
+ * 7. Disclaimer of Warranty. Unless required by applicable law or
+ * agreed to in writing, Licensor provides the Work (and each
+ * Contributor provides its Contributions) on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied, including, without limitation, any warranties or conditions
+ * of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ * PARTICULAR PURPOSE. You are solely responsible for determining the
+ * appropriateness of using or redistributing the Work and assume any
+ * risks associated with Your exercise of permissions under this License.
+ *
+ * 8. Limitation of Liability. In no event and under no legal theory,
+ * whether in tort (including negligence), contract, or otherwise,
+ * unless required by applicable law (such as deliberate and grossly
+ * negligent acts) or agreed to in writing, shall any Contributor be
+ * liable to You for damages, including any direct, indirect, special,
+ * incidental, or consequential damages of any character arising as a
+ * result of this License or out of the use or inability to use the
+ * Work (including but not limited to damages for loss of goodwill,
+ * work stoppage, computer failure or malfunction, or any and all
+ * other commercial damages or losses), even if such Contributor
+ * has been advised of the possibility of such damages.
+ *
+ * 9. Accepting Warranty or Additional Liability. While redistributing
+ * the Work or Derivative Works thereof, You may choose to offer,
+ * and charge a fee for, acceptance of support, warranty, indemnity,
+ * or other liability obligations and/or rights consistent with this
+ * License. However, in accepting such obligations, You may act only
+ * on Your own behalf and on Your sole responsibility, not on behalf
+ * of any other Contributor, and only if You agree to indemnify,
+ * defend, and hold each Contributor harmless for any liability
+ * incurred by, or claims asserted against, such Contributor by reason
+ * of your accepting any such warranty or additional liability.
+ *
+ * END OF TERMS AND CONDITIONS
+ *
+ * APPENDIX: How to apply the Apache License to your work.
+ *
+ * To apply the Apache License to your work, attach the following
+ * boilerplate notice, with the fields enclosed by brackets "{}"
+ * replaced with your own identifying information. (Don't include
+ * the brackets!) The text should be enclosed in the appropriate
+ * comment syntax for the file format. We also recommend that a
+ * file or class name and description of purpose be included on the
+ * same "printed page" as the copyright notice for easier
+ * identification within third-party archives.
+ *
+ * Copyright 2014 Edgar Espina
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jooby.json;
+
+import static java.util.Objects.requireNonNull;
+
+import java.util.function.BiConsumer;
+import java.util.function.Consumer;
+
+import javax.json.Json;
+import javax.json.bind.Jsonb;
+import javax.json.bind.JsonbBuilder;
+import javax.json.bind.JsonbConfig;
+
+import org.jooby.Env;
+import org.jooby.Jooby;
+import org.jooby.MediaType;
+import org.jooby.Parser;
+import org.jooby.Renderer;
+
+import com.google.inject.Binder;
+import com.google.inject.multibindings.Multibinder;
+import com.typesafe.config.Config;
+
+/**
+ * JSON support via Yasson library.
+ *
+ * exposes
+ *
+ *
+ * - A {@link Jsonb}
+ * - A {@link Parser}
+ * - A {@link Renderer}
+ *
+ *
+ * usage
+ *
+ *
+ * {
+ * use(new Yasson());
+ *
+ * // sending
+ * get("/my-api", req {@literal ->} new MyObject());
+ *
+ * // receiving a json body
+ * post("/my-api", req {@literal ->} {
+ * MyObject obj = req.body(MyObject.class);
+ * return obj;
+ * });
+ *
+ * // direct access to Jsonb
+ * get("/access", req {@literal ->} {
+ * Jsonb jsonb = req.require(Jsonb.class);
+ * // ...
+ * });
+ * }
+ *
+ *
+ * configuration
+ *
+ *
+ * If you need a special setting or configuration for your {@link Jsonb}:
+ *
+ *
+ *
+ * {
+ * use(new Yasson().doWith(builder {@literal ->} {
+ * builder.withFormatting(true);
+ * // ...
+ * });
+ * }
+ *
+ *
+ * @author Daniel Dias
+ * @since 1.6.0
+ */
+public class Yasson implements Jooby.Module {
+
+ private final MediaType type;
+
+ private BiConsumer configurer;
+
+ private boolean raw;
+
+ /**
+ * Creates a new {@link Jsonb}.
+ *
+ * @param type {@link MediaType} to use.
+ */
+ public Yasson(final MediaType type) {
+ this.type = requireNonNull(type, "Media type is required.");
+ }
+
+ /**
+ * Creates a new {@link Jsonb} and set type to: {@link MediaType#json}.
+ *
+ */
+ public Yasson() {
+ this(MediaType.json);
+ }
+
+ /**
+ * Configurer callback.
+ *
+ *
+ * {
+ * use(new Yasson().doWith(builder {@literal ->} {
+ * builder.withFormatting(true);
+ * // ...
+ * });
+ * }
+ *
+ *
+ * @param configurer A callback.
+ * @return This instance.
+ */
+ public Yasson doWith(final BiConsumer configurer) {
+ this.configurer = requireNonNull(configurer, "Configurer callback is required.");
+ return this;
+ }
+
+ /**
+ * Configurer callback.
+ *
+ *
+ * {
+ * use(new Yasson().doWith((builder, config) {@literal ->} {
+ * builder.withFormatting(true);
+ * // ...
+ * });
+ * }
+ *
+ *
+ * @param configurer A callback.
+ * @return This instance.
+ */
+ public Yasson doWith(final Consumer configurer) {
+ requireNonNull(configurer, "Configurer callback is required.");
+ this.configurer = (jsonConfig, conf) -> configurer.accept(jsonConfig);
+ return this;
+ }
+
+ @Override
+ public void configure(final Env env, final Config config, final Binder binder) {
+ JsonbConfig jsonbConfig = new JsonbConfig();
+
+ if (configurer != null) {
+ configurer.accept(jsonbConfig, config);
+ }
+
+ Jsonb jsonb = JsonbBuilder.create(jsonbConfig);
+
+ binder.bind(Jsonb.class).toInstance(jsonb);
+
+ Multibinder.newSetBinder(binder, Parser.class).addBinding().toInstance(new YassonParser(type, jsonb));
+
+ YassonRenderer renderer = raw ? new YassonRawRenderer(type, jsonb) : new YassonRenderer(type, jsonb);
+
+ Multibinder.newSetBinder(binder, Renderer.class).addBinding().toInstance(renderer);
+ }
+
+ /**
+ * Add support raw string json responses:
+ *
+ * {@code
+ * {
+ * get("/raw", () -> {
+ * return "{\"raw\": \"json\"}";
+ * });
+ * }
+ * }
+ *
+ * @return This module.
+ */
+ public Yasson raw() {
+ raw = true;
+ return this;
+ }
+}
\ No newline at end of file
diff --git a/modules/jooby-yasson/src/main/java/org/jooby/json/YassonParser.java b/modules/jooby-yasson/src/main/java/org/jooby/json/YassonParser.java
new file mode 100644
index 0000000000..4113412e9b
--- /dev/null
+++ b/modules/jooby-yasson/src/main/java/org/jooby/json/YassonParser.java
@@ -0,0 +1,249 @@
+/**
+ * Apache License
+ * Version 2.0, January 2004
+ * http://www.apache.org/licenses/
+ *
+ * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+ *
+ * 1. Definitions.
+ *
+ * "License" shall mean the terms and conditions for use, reproduction,
+ * and distribution as defined by Sections 1 through 9 of this document.
+ *
+ * "Licensor" shall mean the copyright owner or entity authorized by
+ * the copyright owner that is granting the License.
+ *
+ * "Legal Entity" shall mean the union of the acting entity and all
+ * other entities that control, are controlled by, or are under common
+ * control with that entity. For the purposes of this definition,
+ * "control" means (i) the power, direct or indirect, to cause the
+ * direction or management of such entity, whether by contract or
+ * otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ * outstanding shares, or (iii) beneficial ownership of such entity.
+ *
+ * "You" (or "Your") shall mean an individual or Legal Entity
+ * exercising permissions granted by this License.
+ *
+ * "Source" form shall mean the preferred form for making modifications,
+ * including but not limited to software source code, documentation
+ * source, and configuration files.
+ *
+ * "Object" form shall mean any form resulting from mechanical
+ * transformation or translation of a Source form, including but
+ * not limited to compiled object code, generated documentation,
+ * and conversions to other media types.
+ *
+ * "Work" shall mean the work of authorship, whether in Source or
+ * Object form, made available under the License, as indicated by a
+ * copyright notice that is included in or attached to the work
+ * (an example is provided in the Appendix below).
+ *
+ * "Derivative Works" shall mean any work, whether in Source or Object
+ * form, that is based on (or derived from) the Work and for which the
+ * editorial revisions, annotations, elaborations, or other modifications
+ * represent, as a whole, an original work of authorship. For the purposes
+ * of this License, Derivative Works shall not include works that remain
+ * separable from, or merely link (or bind by name) to the interfaces of,
+ * the Work and Derivative Works thereof.
+ *
+ * "Contribution" shall mean any work of authorship, including
+ * the original version of the Work and any modifications or additions
+ * to that Work or Derivative Works thereof, that is intentionally
+ * submitted to Licensor for inclusion in the Work by the copyright owner
+ * or by an individual or Legal Entity authorized to submit on behalf of
+ * the copyright owner. For the purposes of this definition, "submitted"
+ * means any form of electronic, verbal, or written communication sent
+ * to the Licensor or its representatives, including but not limited to
+ * communication on electronic mailing lists, source code control systems,
+ * and issue tracking systems that are managed by, or on behalf of, the
+ * Licensor for the purpose of discussing and improving the Work, but
+ * excluding communication that is conspicuously marked or otherwise
+ * designated in writing by the copyright owner as "Not a Contribution."
+ *
+ * "Contributor" shall mean Licensor and any individual or Legal Entity
+ * on behalf of whom a Contribution has been received by Licensor and
+ * subsequently incorporated within the Work.
+ *
+ * 2. Grant of Copyright License. Subject to the terms and conditions of
+ * this License, each Contributor hereby grants to You a perpetual,
+ * worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ * copyright license to reproduce, prepare Derivative Works of,
+ * publicly display, publicly perform, sublicense, and distribute the
+ * Work and such Derivative Works in Source or Object form.
+ *
+ * 3. Grant of Patent License. Subject to the terms and conditions of
+ * this License, each Contributor hereby grants to You a perpetual,
+ * worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ * (except as stated in this section) patent license to make, have made,
+ * use, offer to sell, sell, import, and otherwise transfer the Work,
+ * where such license applies only to those patent claims licensable
+ * by such Contributor that are necessarily infringed by their
+ * Contribution(s) alone or by combination of their Contribution(s)
+ * with the Work to which such Contribution(s) was submitted. If You
+ * institute patent litigation against any entity (including a
+ * cross-claim or counterclaim in a lawsuit) alleging that the Work
+ * or a Contribution incorporated within the Work constitutes direct
+ * or contributory patent infringement, then any patent licenses
+ * granted to You under this License for that Work shall terminate
+ * as of the date such litigation is filed.
+ *
+ * 4. Redistribution. You may reproduce and distribute copies of the
+ * Work or Derivative Works thereof in any medium, with or without
+ * modifications, and in Source or Object form, provided that You
+ * meet the following conditions:
+ *
+ * (a) You must give any other recipients of the Work or
+ * Derivative Works a copy of this License; and
+ *
+ * (b) You must cause any modified files to carry prominent notices
+ * stating that You changed the files; and
+ *
+ * (c) You must retain, in the Source form of any Derivative Works
+ * that You distribute, all copyright, patent, trademark, and
+ * attribution notices from the Source form of the Work,
+ * excluding those notices that do not pertain to any part of
+ * the Derivative Works; and
+ *
+ * (d) If the Work includes a "NOTICE" text file as part of its
+ * distribution, then any Derivative Works that You distribute must
+ * include a readable copy of the attribution notices contained
+ * within such NOTICE file, excluding those notices that do not
+ * pertain to any part of the Derivative Works, in at least one
+ * of the following places: within a NOTICE text file distributed
+ * as part of the Derivative Works; within the Source form or
+ * documentation, if provided along with the Derivative Works; or,
+ * within a display generated by the Derivative Works, if and
+ * wherever such third-party notices normally appear. The contents
+ * of the NOTICE file are for informational purposes only and
+ * do not modify the License. You may add Your own attribution
+ * notices within Derivative Works that You distribute, alongside
+ * or as an addendum to the NOTICE text from the Work, provided
+ * that such additional attribution notices cannot be construed
+ * as modifying the License.
+ *
+ * You may add Your own copyright statement to Your modifications and
+ * may provide additional or different license terms and conditions
+ * for use, reproduction, or distribution of Your modifications, or
+ * for any such Derivative Works as a whole, provided Your use,
+ * reproduction, and distribution of the Work otherwise complies with
+ * the conditions stated in this License.
+ *
+ * 5. Submission of Contributions. Unless You explicitly state otherwise,
+ * any Contribution intentionally submitted for inclusion in the Work
+ * by You to the Licensor shall be under the terms and conditions of
+ * this License, without any additional terms or conditions.
+ * Notwithstanding the above, nothing herein shall supersede or modify
+ * the terms of any separate license agreement you may have executed
+ * with Licensor regarding such Contributions.
+ *
+ * 6. Trademarks. This License does not grant permission to use the trade
+ * names, trademarks, service marks, or product names of the Licensor,
+ * except as required for reasonable and customary use in describing the
+ * origin of the Work and reproducing the content of the NOTICE file.
+ *
+ * 7. Disclaimer of Warranty. Unless required by applicable law or
+ * agreed to in writing, Licensor provides the Work (and each
+ * Contributor provides its Contributions) on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied, including, without limitation, any warranties or conditions
+ * of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ * PARTICULAR PURPOSE. You are solely responsible for determining the
+ * appropriateness of using or redistributing the Work and assume any
+ * risks associated with Your exercise of permissions under this License.
+ *
+ * 8. Limitation of Liability. In no event and under no legal theory,
+ * whether in tort (including negligence), contract, or otherwise,
+ * unless required by applicable law (such as deliberate and grossly
+ * negligent acts) or agreed to in writing, shall any Contributor be
+ * liable to You for damages, including any direct, indirect, special,
+ * incidental, or consequential damages of any character arising as a
+ * result of this License or out of the use or inability to use the
+ * Work (including but not limited to damages for loss of goodwill,
+ * work stoppage, computer failure or malfunction, or any and all
+ * other commercial damages or losses), even if such Contributor
+ * has been advised of the possibility of such damages.
+ *
+ * 9. Accepting Warranty or Additional Liability. While redistributing
+ * the Work or Derivative Works thereof, You may choose to offer,
+ * and charge a fee for, acceptance of support, warranty, indemnity,
+ * or other liability obligations and/or rights consistent with this
+ * License. However, in accepting such obligations, You may act only
+ * on Your own behalf and on Your sole responsibility, not on behalf
+ * of any other Contributor, and only if You agree to indemnify,
+ * defend, and hold each Contributor harmless for any liability
+ * incurred by, or claims asserted against, such Contributor by reason
+ * of your accepting any such warranty or additional liability.
+ *
+ * END OF TERMS AND CONDITIONS
+ *
+ * APPENDIX: How to apply the Apache License to your work.
+ *
+ * To apply the Apache License to your work, attach the following
+ * boilerplate notice, with the fields enclosed by brackets "{}"
+ * replaced with your own identifying information. (Don't include
+ * the brackets!) The text should be enclosed in the appropriate
+ * comment syntax for the file format. We also recommend that a
+ * file or class name and description of purpose be included on the
+ * same "printed page" as the copyright notice for easier
+ * identification within third-party archives.
+ *
+ * Copyright 2014 Edgar Espina
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jooby.json;
+
+import static java.util.Objects.requireNonNull;
+import javax.json.bind.Jsonb;
+
+import org.jooby.MediaType;
+import org.jooby.Parser;
+import org.jooby.Parser.Context;
+
+import com.google.inject.TypeLiteral;
+
+ /**
+ * @author Daniel Dias
+ * @since 1.6.0
+ */
+class YassonParser implements Parser {
+
+ private final MediaType type;
+
+ private final Jsonb jsonb;
+
+ public YassonParser(final MediaType type, final Jsonb jsonb) {
+ this.type = requireNonNull(type, "Media type is required.");
+ this.jsonb = requireNonNull(jsonb, "Jsonb is required.");
+ }
+
+ @Override
+ public Object parse(final TypeLiteral> type, final Context ctx) throws Throwable {
+ MediaType ctype = ctx.type();
+ if (ctype.isAny()) {
+ return ctx.next();
+ }
+
+ if (ctype.matches(this.type)) {
+ return ctx
+ .ifbody(body -> jsonb.fromJson(body.text(), type.getType()))
+ .ifparam(values -> jsonb.fromJson(values.first(), type.getType()));
+ }
+ return ctx.next();
+ }
+
+ @Override
+ public String toString() {
+ return "yasson";
+ }
+}
\ No newline at end of file
diff --git a/modules/jooby-yasson/src/main/java/org/jooby/json/YassonRawRenderer.java b/modules/jooby-yasson/src/main/java/org/jooby/json/YassonRawRenderer.java
new file mode 100644
index 0000000000..47169063b6
--- /dev/null
+++ b/modules/jooby-yasson/src/main/java/org/jooby/json/YassonRawRenderer.java
@@ -0,0 +1,229 @@
+/**
+ * Apache License
+ * Version 2.0, January 2004
+ * http://www.apache.org/licenses/
+ *
+ * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+ *
+ * 1. Definitions.
+ *
+ * "License" shall mean the terms and conditions for use, reproduction,
+ * and distribution as defined by Sections 1 through 9 of this document.
+ *
+ * "Licensor" shall mean the copyright owner or entity authorized by
+ * the copyright owner that is granting the License.
+ *
+ * "Legal Entity" shall mean the union of the acting entity and all
+ * other entities that control, are controlled by, or are under common
+ * control with that entity. For the purposes of this definition,
+ * "control" means (i) the power, direct or indirect, to cause the
+ * direction or management of such entity, whether by contract or
+ * otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ * outstanding shares, or (iii) beneficial ownership of such entity.
+ *
+ * "You" (or "Your") shall mean an individual or Legal Entity
+ * exercising permissions granted by this License.
+ *
+ * "Source" form shall mean the preferred form for making modifications,
+ * including but not limited to software source code, documentation
+ * source, and configuration files.
+ *
+ * "Object" form shall mean any form resulting from mechanical
+ * transformation or translation of a Source form, including but
+ * not limited to compiled object code, generated documentation,
+ * and conversions to other media types.
+ *
+ * "Work" shall mean the work of authorship, whether in Source or
+ * Object form, made available under the License, as indicated by a
+ * copyright notice that is included in or attached to the work
+ * (an example is provided in the Appendix below).
+ *
+ * "Derivative Works" shall mean any work, whether in Source or Object
+ * form, that is based on (or derived from) the Work and for which the
+ * editorial revisions, annotations, elaborations, or other modifications
+ * represent, as a whole, an original work of authorship. For the purposes
+ * of this License, Derivative Works shall not include works that remain
+ * separable from, or merely link (or bind by name) to the interfaces of,
+ * the Work and Derivative Works thereof.
+ *
+ * "Contribution" shall mean any work of authorship, including
+ * the original version of the Work and any modifications or additions
+ * to that Work or Derivative Works thereof, that is intentionally
+ * submitted to Licensor for inclusion in the Work by the copyright owner
+ * or by an individual or Legal Entity authorized to submit on behalf of
+ * the copyright owner. For the purposes of this definition, "submitted"
+ * means any form of electronic, verbal, or written communication sent
+ * to the Licensor or its representatives, including but not limited to
+ * communication on electronic mailing lists, source code control systems,
+ * and issue tracking systems that are managed by, or on behalf of, the
+ * Licensor for the purpose of discussing and improving the Work, but
+ * excluding communication that is conspicuously marked or otherwise
+ * designated in writing by the copyright owner as "Not a Contribution."
+ *
+ * "Contributor" shall mean Licensor and any individual or Legal Entity
+ * on behalf of whom a Contribution has been received by Licensor and
+ * subsequently incorporated within the Work.
+ *
+ * 2. Grant of Copyright License. Subject to the terms and conditions of
+ * this License, each Contributor hereby grants to You a perpetual,
+ * worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ * copyright license to reproduce, prepare Derivative Works of,
+ * publicly display, publicly perform, sublicense, and distribute the
+ * Work and such Derivative Works in Source or Object form.
+ *
+ * 3. Grant of Patent License. Subject to the terms and conditions of
+ * this License, each Contributor hereby grants to You a perpetual,
+ * worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ * (except as stated in this section) patent license to make, have made,
+ * use, offer to sell, sell, import, and otherwise transfer the Work,
+ * where such license applies only to those patent claims licensable
+ * by such Contributor that are necessarily infringed by their
+ * Contribution(s) alone or by combination of their Contribution(s)
+ * with the Work to which such Contribution(s) was submitted. If You
+ * institute patent litigation against any entity (including a
+ * cross-claim or counterclaim in a lawsuit) alleging that the Work
+ * or a Contribution incorporated within the Work constitutes direct
+ * or contributory patent infringement, then any patent licenses
+ * granted to You under this License for that Work shall terminate
+ * as of the date such litigation is filed.
+ *
+ * 4. Redistribution. You may reproduce and distribute copies of the
+ * Work or Derivative Works thereof in any medium, with or without
+ * modifications, and in Source or Object form, provided that You
+ * meet the following conditions:
+ *
+ * (a) You must give any other recipients of the Work or
+ * Derivative Works a copy of this License; and
+ *
+ * (b) You must cause any modified files to carry prominent notices
+ * stating that You changed the files; and
+ *
+ * (c) You must retain, in the Source form of any Derivative Works
+ * that You distribute, all copyright, patent, trademark, and
+ * attribution notices from the Source form of the Work,
+ * excluding those notices that do not pertain to any part of
+ * the Derivative Works; and
+ *
+ * (d) If the Work includes a "NOTICE" text file as part of its
+ * distribution, then any Derivative Works that You distribute must
+ * include a readable copy of the attribution notices contained
+ * within such NOTICE file, excluding those notices that do not
+ * pertain to any part of the Derivative Works, in at least one
+ * of the following places: within a NOTICE text file distributed
+ * as part of the Derivative Works; within the Source form or
+ * documentation, if provided along with the Derivative Works; or,
+ * within a display generated by the Derivative Works, if and
+ * wherever such third-party notices normally appear. The contents
+ * of the NOTICE file are for informational purposes only and
+ * do not modify the License. You may add Your own attribution
+ * notices within Derivative Works that You distribute, alongside
+ * or as an addendum to the NOTICE text from the Work, provided
+ * that such additional attribution notices cannot be construed
+ * as modifying the License.
+ *
+ * You may add Your own copyright statement to Your modifications and
+ * may provide additional or different license terms and conditions
+ * for use, reproduction, or distribution of Your modifications, or
+ * for any such Derivative Works as a whole, provided Your use,
+ * reproduction, and distribution of the Work otherwise complies with
+ * the conditions stated in this License.
+ *
+ * 5. Submission of Contributions. Unless You explicitly state otherwise,
+ * any Contribution intentionally submitted for inclusion in the Work
+ * by You to the Licensor shall be under the terms and conditions of
+ * this License, without any additional terms or conditions.
+ * Notwithstanding the above, nothing herein shall supersede or modify
+ * the terms of any separate license agreement you may have executed
+ * with Licensor regarding such Contributions.
+ *
+ * 6. Trademarks. This License does not grant permission to use the trade
+ * names, trademarks, service marks, or product names of the Licensor,
+ * except as required for reasonable and customary use in describing the
+ * origin of the Work and reproducing the content of the NOTICE file.
+ *
+ * 7. Disclaimer of Warranty. Unless required by applicable law or
+ * agreed to in writing, Licensor provides the Work (and each
+ * Contributor provides its Contributions) on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied, including, without limitation, any warranties or conditions
+ * of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ * PARTICULAR PURPOSE. You are solely responsible for determining the
+ * appropriateness of using or redistributing the Work and assume any
+ * risks associated with Your exercise of permissions under this License.
+ *
+ * 8. Limitation of Liability. In no event and under no legal theory,
+ * whether in tort (including negligence), contract, or otherwise,
+ * unless required by applicable law (such as deliberate and grossly
+ * negligent acts) or agreed to in writing, shall any Contributor be
+ * liable to You for damages, including any direct, indirect, special,
+ * incidental, or consequential damages of any character arising as a
+ * result of this License or out of the use or inability to use the
+ * Work (including but not limited to damages for loss of goodwill,
+ * work stoppage, computer failure or malfunction, or any and all
+ * other commercial damages or losses), even if such Contributor
+ * has been advised of the possibility of such damages.
+ *
+ * 9. Accepting Warranty or Additional Liability. While redistributing
+ * the Work or Derivative Works thereof, You may choose to offer,
+ * and charge a fee for, acceptance of support, warranty, indemnity,
+ * or other liability obligations and/or rights consistent with this
+ * License. However, in accepting such obligations, You may act only
+ * on Your own behalf and on Your sole responsibility, not on behalf
+ * of any other Contributor, and only if You agree to indemnify,
+ * defend, and hold each Contributor harmless for any liability
+ * incurred by, or claims asserted against, such Contributor by reason
+ * of your accepting any such warranty or additional liability.
+ *
+ * END OF TERMS AND CONDITIONS
+ *
+ * APPENDIX: How to apply the Apache License to your work.
+ *
+ * To apply the Apache License to your work, attach the following
+ * boilerplate notice, with the fields enclosed by brackets "{}"
+ * replaced with your own identifying information. (Don't include
+ * the brackets!) The text should be enclosed in the appropriate
+ * comment syntax for the file format. We also recommend that a
+ * file or class name and description of purpose be included on the
+ * same "printed page" as the copyright notice for easier
+ * identification within third-party archives.
+ *
+ * Copyright 2014 Edgar Espina
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.jooby.json;
+
+import javax.json.bind.Jsonb;
+
+import org.jooby.MediaType;
+
+/**
+ * @author Daniel Dias
+ * @since 1.6.0
+ */
+public class YassonRawRenderer extends YassonRenderer {
+
+ public YassonRawRenderer(MediaType type, Jsonb jsonb) {
+ super(type, jsonb);
+ }
+
+ @Override
+ public void render(Object value, Context ctx) throws Exception {
+ if (value instanceof CharSequence) {
+ ctx.type(type).send(value.toString());
+ } else {
+ super.render(value, ctx);
+ }
+ }
+}
\ No newline at end of file
diff --git a/modules/jooby-yasson/src/main/java/org/jooby/json/YassonRenderer.java b/modules/jooby-yasson/src/main/java/org/jooby/json/YassonRenderer.java
new file mode 100644
index 0000000000..7fcebdc205
--- /dev/null
+++ b/modules/jooby-yasson/src/main/java/org/jooby/json/YassonRenderer.java
@@ -0,0 +1,245 @@
+/**
+ * Apache License
+ * Version 2.0, January 2004
+ * http://www.apache.org/licenses/
+ *
+ * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+ *
+ * 1. Definitions.
+ *
+ * "License" shall mean the terms and conditions for use, reproduction,
+ * and distribution as defined by Sections 1 through 9 of this document.
+ *
+ * "Licensor" shall mean the copyright owner or entity authorized by
+ * the copyright owner that is granting the License.
+ *
+ * "Legal Entity" shall mean the union of the acting entity and all
+ * other entities that control, are controlled by, or are under common
+ * control with that entity. For the purposes of this definition,
+ * "control" means (i) the power, direct or indirect, to cause the
+ * direction or management of such entity, whether by contract or
+ * otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ * outstanding shares, or (iii) beneficial ownership of such entity.
+ *
+ * "You" (or "Your") shall mean an individual or Legal Entity
+ * exercising permissions granted by this License.
+ *
+ * "Source" form shall mean the preferred form for making modifications,
+ * including but not limited to software source code, documentation
+ * source, and configuration files.
+ *
+ * "Object" form shall mean any form resulting from mechanical
+ * transformation or translation of a Source form, including but
+ * not limited to compiled object code, generated documentation,
+ * and conversions to other media types.
+ *
+ * "Work" shall mean the work of authorship, whether in Source or
+ * Object form, made available under the License, as indicated by a
+ * copyright notice that is included in or attached to the work
+ * (an example is provided in the Appendix below).
+ *
+ * "Derivative Works" shall mean any work, whether in Source or Object
+ * form, that is based on (or derived from) the Work and for which the
+ * editorial revisions, annotations, elaborations, or other modifications
+ * represent, as a whole, an original work of authorship. For the purposes
+ * of this License, Derivative Works shall not include works that remain
+ * separable from, or merely link (or bind by name) to the interfaces of,
+ * the Work and Derivative Works thereof.
+ *
+ * "Contribution" shall mean any work of authorship, including
+ * the original version of the Work and any modifications or additions
+ * to that Work or Derivative Works thereof, that is intentionally
+ * submitted to Licensor for inclusion in the Work by the copyright owner
+ * or by an individual or Legal Entity authorized to submit on behalf of
+ * the copyright owner. For the purposes of this definition, "submitted"
+ * means any form of electronic, verbal, or written communication sent
+ * to the Licensor or its representatives, including but not limited to
+ * communication on electronic mailing lists, source code control systems,
+ * and issue tracking systems that are managed by, or on behalf of, the
+ * Licensor for the purpose of discussing and improving the Work, but
+ * excluding communication that is conspicuously marked or otherwise
+ * designated in writing by the copyright owner as "Not a Contribution."
+ *
+ * "Contributor" shall mean Licensor and any individual or Legal Entity
+ * on behalf of whom a Contribution has been received by Licensor and
+ * subsequently incorporated within the Work.
+ *
+ * 2. Grant of Copyright License. Subject to the terms and conditions of
+ * this License, each Contributor hereby grants to You a perpetual,
+ * worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ * copyright license to reproduce, prepare Derivative Works of,
+ * publicly display, publicly perform, sublicense, and distribute the
+ * Work and such Derivative Works in Source or Object form.
+ *
+ * 3. Grant of Patent License. Subject to the terms and conditions of
+ * this License, each Contributor hereby grants to You a perpetual,
+ * worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ * (except as stated in this section) patent license to make, have made,
+ * use, offer to sell, sell, import, and otherwise transfer the Work,
+ * where such license applies only to those patent claims licensable
+ * by such Contributor that are necessarily infringed by their
+ * Contribution(s) alone or by combination of their Contribution(s)
+ * with the Work to which such Contribution(s) was submitted. If You
+ * institute patent litigation against any entity (including a
+ * cross-claim or counterclaim in a lawsuit) alleging that the Work
+ * or a Contribution incorporated within the Work constitutes direct
+ * or contributory patent infringement, then any patent licenses
+ * granted to You under this License for that Work shall terminate
+ * as of the date such litigation is filed.
+ *
+ * 4. Redistribution. You may reproduce and distribute copies of the
+ * Work or Derivative Works thereof in any medium, with or without
+ * modifications, and in Source or Object form, provided that You
+ * meet the following conditions:
+ *
+ * (a) You must give any other recipients of the Work or
+ * Derivative Works a copy of this License; and
+ *
+ * (b) You must cause any modified files to carry prominent notices
+ * stating that You changed the files; and
+ *
+ * (c) You must retain, in the Source form of any Derivative Works
+ * that You distribute, all copyright, patent, trademark, and
+ * attribution notices from the Source form of the Work,
+ * excluding those notices that do not pertain to any part of
+ * the Derivative Works; and
+ *
+ * (d) If the Work includes a "NOTICE" text file as part of its
+ * distribution, then any Derivative Works that You distribute must
+ * include a readable copy of the attribution notices contained
+ * within such NOTICE file, excluding those notices that do not
+ * pertain to any part of the Derivative Works, in at least one
+ * of the following places: within a NOTICE text file distributed
+ * as part of the Derivative Works; within the Source form or
+ * documentation, if provided along with the Derivative Works; or,
+ * within a display generated by the Derivative Works, if and
+ * wherever such third-party notices normally appear. The contents
+ * of the NOTICE file are for informational purposes only and
+ * do not modify the License. You may add Your own attribution
+ * notices within Derivative Works that You distribute, alongside
+ * or as an addendum to the NOTICE text from the Work, provided
+ * that such additional attribution notices cannot be construed
+ * as modifying the License.
+ *
+ * You may add Your own copyright statement to Your modifications and
+ * may provide additional or different license terms and conditions
+ * for use, reproduction, or distribution of Your modifications, or
+ * for any such Derivative Works as a whole, provided Your use,
+ * reproduction, and distribution of the Work otherwise complies with
+ * the conditions stated in this License.
+ *
+ * 5. Submission of Contributions. Unless You explicitly state otherwise,
+ * any Contribution intentionally submitted for inclusion in the Work
+ * by You to the Licensor shall be under the terms and conditions of
+ * this License, without any additional terms or conditions.
+ * Notwithstanding the above, nothing herein shall supersede or modify
+ * the terms of any separate license agreement you may have executed
+ * with Licensor regarding such Contributions.
+ *
+ * 6. Trademarks. This License does not grant permission to use the trade
+ * names, trademarks, service marks, or product names of the Licensor,
+ * except as required for reasonable and customary use in describing the
+ * origin of the Work and reproducing the content of the NOTICE file.
+ *
+ * 7. Disclaimer of Warranty. Unless required by applicable law or
+ * agreed to in writing, Licensor provides the Work (and each
+ * Contributor provides its Contributions) on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied, including, without limitation, any warranties or conditions
+ * of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ * PARTICULAR PURPOSE. You are solely responsible for determining the
+ * appropriateness of using or redistributing the Work and assume any
+ * risks associated with Your exercise of permissions under this License.
+ *
+ * 8. Limitation of Liability. In no event and under no legal theory,
+ * whether in tort (including negligence), contract, or otherwise,
+ * unless required by applicable law (such as deliberate and grossly
+ * negligent acts) or agreed to in writing, shall any Contributor be
+ * liable to You for damages, including any direct, indirect, special,
+ * incidental, or consequential damages of any character arising as a
+ * result of this License or out of the use or inability to use the
+ * Work (including but not limited to damages for loss of goodwill,
+ * work stoppage, computer failure or malfunction, or any and all
+ * other commercial damages or losses), even if such Contributor
+ * has been advised of the possibility of such damages.
+ *
+ * 9. Accepting Warranty or Additional Liability. While redistributing
+ * the Work or Derivative Works thereof, You may choose to offer,
+ * and charge a fee for, acceptance of support, warranty, indemnity,
+ * or other liability obligations and/or rights consistent with this
+ * License. However, in accepting such obligations, You may act only
+ * on Your own behalf and on Your sole responsibility, not on behalf
+ * of any other Contributor, and only if You agree to indemnify,
+ * defend, and hold each Contributor harmless for any liability
+ * incurred by, or claims asserted against, such Contributor by reason
+ * of your accepting any such warranty or additional liability.
+ *
+ * END OF TERMS AND CONDITIONS
+ *
+ * APPENDIX: How to apply the Apache License to your work.
+ *
+ * To apply the Apache License to your work, attach the following
+ * boilerplate notice, with the fields enclosed by brackets "{}"
+ * replaced with your own identifying information. (Don't include
+ * the brackets!) The text should be enclosed in the appropriate
+ * comment syntax for the file format. We also recommend that a
+ * file or class name and description of purpose be included on the
+ * same "printed page" as the copyright notice for easier
+ * identification within third-party archives.
+ *
+ * Copyright 2014 Edgar Espina
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jooby.json;
+
+import static java.util.Objects.requireNonNull;
+
+import javax.json.bind.Jsonb;
+
+import org.jooby.MediaType;
+import org.jooby.Renderer;
+
+ /**
+ * @author Daniel Dias
+ * @since 1.6.0
+ */
+public class YassonRenderer implements Renderer {
+
+ protected final MediaType type;
+
+ private final Jsonb jsonb;
+
+ public YassonRenderer(final MediaType type, final Jsonb jsonb) {
+ this.type = requireNonNull(type, "Media type is required.");
+
+ this.jsonb = requireNonNull(jsonb, "Jsonb is required.");
+ }
+
+ @Override
+ public void render(final Object object, final Context ctx) throws Exception {
+ if (ctx.accepts(this.type)) {
+ ctx.type(this.type).send(jsonb.toJson(object));
+ }
+ }
+
+ @Override
+ public String name() {
+ return "json";
+ }
+
+ @Override
+ public String toString() {
+ return name();
+ }
+}
\ No newline at end of file
diff --git a/modules/jooby-yasson/src/test/java/org/jooby/json/YassonParserTest.java b/modules/jooby-yasson/src/test/java/org/jooby/json/YassonParserTest.java
new file mode 100644
index 0000000000..5b4f6e618d
--- /dev/null
+++ b/modules/jooby-yasson/src/test/java/org/jooby/json/YassonParserTest.java
@@ -0,0 +1,124 @@
+package org.jooby.json;
+
+import static org.easymock.EasyMock.expect;
+import static org.junit.Assert.assertEquals;
+
+import javax.json.bind.Jsonb;
+
+import org.jooby.MediaType;
+import org.jooby.Parser;
+import org.jooby.Parser.Context;
+import org.jooby.test.MockUnit;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+import com.google.inject.TypeLiteral;
+
+@RunWith(PowerMockRunner.class)
+@PrepareForTest({YassonParser.class, Jsonb.class })
+public class YassonParserTest {
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void parseBody() throws Exception {
+ TypeLiteral type = TypeLiteral.get(YassonParserTest.class);
+ Object value = new Object();
+ new MockUnit(Jsonb.class, Parser.Context.class, Parser.BodyReference.class)
+ .expect(unit -> {
+ Context ctx = unit.get(Parser.Context.class);
+ expect(ctx.type()).andReturn(MediaType.json);
+
+ Parser.Builder builder = unit.mock(Parser.Builder.class);
+
+ expect(ctx.ifbody(unit.capture(Parser.Callback.class))).andReturn(builder);
+ expect(builder.ifparam(unit.capture(Parser.Callback.class))).andReturn(builder);
+ })
+ .expect(unit -> {
+ Parser.BodyReference ref = unit.get(Parser.BodyReference.class);
+ expect(ref.text()).andReturn("{}");
+ })
+ .expect(unit -> {
+ Jsonb jsonb = unit.get(Jsonb.class);
+ expect(jsonb.fromJson("{}", type.getType())).andReturn(value);
+ })
+ .run(unit -> {
+ new YassonParser(MediaType.json, unit.get(Jsonb.class))
+ .parse(type, unit.get(Parser.Context.class));
+ }, unit -> {
+ unit.captured(Parser.Callback.class).iterator().next()
+ .invoke(unit.get(Parser.BodyReference.class));
+ });
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void parseParam() throws Exception {
+ TypeLiteral type = TypeLiteral.get(YassonParserTest.class);
+ Object value = new Object();
+ new MockUnit(Jsonb.class, Parser.Context.class, Parser.ParamReference.class)
+ .expect(unit -> {
+ Context ctx = unit.get(Parser.Context.class);
+ expect(ctx.type()).andReturn(MediaType.json);
+
+ Parser.Builder builder = unit.mock(Parser.Builder.class);
+
+ expect(ctx.ifbody(unit.capture(Parser.Callback.class))).andReturn(builder);
+ expect(builder.ifparam(unit.capture(Parser.Callback.class))).andReturn(builder);
+ })
+ .expect(unit -> {
+ Parser.ParamReference ref = unit.get(Parser.ParamReference.class);
+ expect(ref.first()).andReturn("{}");
+ })
+ .expect(unit -> {
+ Jsonb jsonb = unit.get(Jsonb.class);
+ expect(jsonb.fromJson("{}", type.getType())).andReturn(value);
+ })
+ .run(unit -> {
+ new YassonParser(MediaType.json, unit.get(Jsonb.class))
+ .parse(type, unit.get(Parser.Context.class));
+ }, unit -> {
+ unit.captured(Parser.Callback.class).get(1)
+ .invoke(unit.get(Parser.ParamReference.class));
+ });
+ }
+
+ @Test
+ public void next() throws Exception {
+ TypeLiteral type = TypeLiteral.get(YassonParserTest.class);
+ new MockUnit(Jsonb.class, Parser.Context.class, Parser.BodyReference.class)
+ .expect(unit -> {
+ Context ctx = unit.get(Parser.Context.class);
+ expect(ctx.type()).andReturn(MediaType.html);
+ expect(ctx.next()).andReturn(null);
+ })
+ .run(unit -> {
+ new YassonParser(MediaType.json, unit.get(Jsonb.class))
+ .parse(type, unit.get(Parser.Context.class));
+ });
+ }
+
+ @Test
+ public void nextAny() throws Exception {
+ TypeLiteral type = TypeLiteral.get(YassonParserTest.class);
+ new MockUnit(Jsonb.class, Parser.Context.class, Parser.BodyReference.class)
+ .expect(unit -> {
+ Context ctx = unit.get(Parser.Context.class);
+ expect(ctx.type()).andReturn(MediaType.all);
+ expect(ctx.next()).andReturn(null);
+ })
+ .run(unit -> {
+ new YassonParser(MediaType.json, unit.get(Jsonb.class))
+ .parse(type, unit.get(Parser.Context.class));
+ });
+ }
+
+ @Test
+ public void toStr() throws Exception {
+ new MockUnit(Jsonb.class)
+ .run(unit -> {
+ assertEquals("yasson", new YassonParser(MediaType.json, unit.get(Jsonb.class)).toString());
+ });
+ }
+
+}
diff --git a/modules/jooby-yasson/src/test/java/org/jooby/json/YassonRendererTest.java b/modules/jooby-yasson/src/test/java/org/jooby/json/YassonRendererTest.java
new file mode 100644
index 0000000000..988fbf63cd
--- /dev/null
+++ b/modules/jooby-yasson/src/test/java/org/jooby/json/YassonRendererTest.java
@@ -0,0 +1,102 @@
+package org.jooby.json;
+
+import static org.easymock.EasyMock.expect;
+import static org.junit.Assert.assertEquals;
+
+import javax.json.bind.Jsonb;
+
+import org.jooby.MediaType;
+import org.jooby.Renderer;
+import org.jooby.Renderer.Context;
+import org.jooby.test.MockUnit;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+@RunWith(PowerMockRunner.class)
+@PrepareForTest({YassonRenderer.class, Jsonb.class })
+public class YassonRendererTest {
+
+ @Test
+ public void render() throws Exception {
+ Object value = new YassonRendererTest();
+ new MockUnit(Jsonb.class, Renderer.Context.class)
+ .expect(unit -> {
+ Context ctx = unit.get(Renderer.Context.class);
+ expect(ctx.accepts(MediaType.json)).andReturn(true);
+ expect(ctx.type(MediaType.json)).andReturn(ctx);
+ ctx.send("{}");
+ })
+ .expect(unit -> {
+ Jsonb gson = unit.get(Jsonb.class);
+ expect(gson.toJson(value)).andReturn("{}");
+ })
+ .run(unit -> {
+ new YassonRenderer(MediaType.json, unit.get(Jsonb.class))
+ .render(value, unit.get(Renderer.Context.class));
+ }, unit -> {
+ });
+ }
+
+ @Test
+ public void renderSkip() throws Exception {
+ Object value = new YassonRendererTest();
+ new MockUnit(Jsonb.class, Renderer.Context.class)
+ .expect(unit -> {
+ Context ctx = unit.get(Renderer.Context.class);
+ expect(ctx.accepts(MediaType.json)).andReturn(false);
+ })
+ .run(unit -> {
+ new YassonRenderer(MediaType.json, unit.get(Jsonb.class))
+ .render(value, unit.get(Renderer.Context.class));
+ }, unit -> {
+ });
+ }
+
+ @Test
+ public void toStr() throws Exception {
+ new MockUnit(Jsonb.class)
+ .run(unit -> {
+ assertEquals("json", new YassonRenderer(MediaType.json, unit.get(Jsonb.class)).toString());
+ });
+ }
+
+ @Test
+ public void rawWithCharSequence() throws Exception {
+ String value = "{\"foo\":\"bar\"}";
+ new MockUnit(Jsonb.class, Renderer.Context.class)
+ .expect(unit -> {
+ Context ctx = unit.get(Renderer.Context.class);
+ expect(ctx.type(MediaType.json)).andReturn(ctx);
+ ctx.send(value);
+ })
+ .run(unit -> {
+ new YassonRawRenderer(MediaType.json, unit.get(Jsonb.class))
+ .render(value, unit.get(Renderer.Context.class));
+ }, unit -> {
+ });
+ }
+
+ @Test
+ public void rawWithObject() throws Exception {
+ Object value = new YassonRendererTest();
+ new MockUnit(Jsonb.class, Renderer.Context.class)
+ .expect(unit -> {
+ Context ctx = unit.get(Renderer.Context.class);
+ expect(ctx.accepts(MediaType.json)).andReturn(true);
+ expect(ctx.type(MediaType.json)).andReturn(ctx);
+ ctx.send("{}");
+ })
+ .expect(unit -> {
+ Jsonb gson = unit.get(Jsonb.class);
+ expect(gson.toJson(value)).andReturn("{}");
+ })
+ .run(unit -> {
+ new YassonRawRenderer(MediaType.json, unit.get(Jsonb.class))
+ .render(value, unit.get(Renderer.Context.class));
+ }, unit -> {
+ });
+ }
+
+}
diff --git a/modules/pom.xml b/modules/pom.xml
index f33aed46cf..4d9ebc8b33 100644
--- a/modules/pom.xml
+++ b/modules/pom.xml
@@ -6,13 +6,14 @@
org.jooby
jooby-project
- 1.5.1-SNAPSHOT
+ 1.6.9
modules
pom
+ jooby-exposed
jooby-apitool
jooby-executor
jooby-jackson
@@ -80,6 +81,7 @@
jooby-rocker
jooby-livereload
jooby-eventbus
+ jooby-yasson
jooby-frontend
jooby-assets
diff --git a/pom.xml b/pom.xml
index b553c219d3..a3788ad87a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
4.0.0
org.jooby
jooby-project
- 1.5.1-SNAPSHOT
+ 1.6.9
pom
jooby-project
@@ -83,6 +83,12 @@
${jooby.version}
+
+ org.jooby
+ jooby-exposed
+ ${jooby.version}
+
+
org.jooby
jooby-executor
@@ -125,6 +131,12 @@
${jooby.version}
+
+ org.jooby
+ jooby-yasson
+ ${jooby.version}
+
+
org.jooby
jooby-maven-plugin
@@ -609,9 +621,9 @@
- io.github.lukehutch
- fast-classpath-scanner
- ${fast-classpath-scanner.version}
+ io.github.classgraph
+ classgraph
+ ${classgraph.version}
@@ -899,6 +911,19 @@
${gson.version}
+
+
+ org.eclipse
+ yasson
+ ${yasson.version}
+
+
+
+ org.glassfish
+ javax.json
+ ${javax.json.version}
+
+
org.jdbi
@@ -1089,14 +1114,21 @@
org.elasticsearch.client
- rest
- ${elasticsearch}
+ elasticsearch-rest-high-level-client
+ ${elasticsearch.version}
+
+
+
+
+ javax.enterprise
+ cdi-api
+ ${cdi-api.version}
org.hibernate
- hibernate-entitymanager
+ hibernate-core
${hibernate.version}
@@ -1114,7 +1146,7 @@
- org.glassfish.web
+ org.glassfish
javax.el
${javax.el-ref.version}
@@ -1612,6 +1644,12 @@
+
+ org.crashub
+ crash.cli
+ ${crash.version}
+
+
org.crashub
crash.connectors.telnet
@@ -3117,14 +3155,15 @@ org.eclipse.jdt.apt.processorOptions/defaultOverwrite=true
2.5.13
4.7
3.0.17
- 6.2
+ 7.3.1
1.9.40
2.1.2
1.11.358
3.3.4
- 2.0.8.Final
+ 2.0.25.Final
2.9.2
2.6.2
+ 1.1
2.18.3
3.2.6
v20180610
@@ -3142,7 +3181,7 @@ org.eclipse.jdt.apt.processorOptions/defaultOverwrite=true
11.11.2
11.18.2
2.10.5
- 5.5.3
+ 7.5.0
5.1.3
2.3.28
1.6
@@ -3150,29 +3189,31 @@ org.eclipse.jdt.apt.processorOptions/defaultOverwrite=true
2.5.0
25.1-jre
2.8.5
+ 1.0.1
+ 1.1
4.2.0
1.4.197
4.1.0
- 3.10.2
+ 3.11
5.1.3.Final
- 5.2.1.Final
- 3.2.0
+ 5.3.9.Final
+ 3.3.1
4.5.5
4.6.0
- 2.9.6
+ 2.10.1
1.2.7
3.22.0-GA
- 2.2.5
- 2.2.6
+ 3.0.1-b06
+ 3.0.1-b10
1
2.0
1.8.5.Final
3.9.0
2.78
- 3.3.0
+ 3.11.1
2.9.0
1.19.4
- 9.4.10.v20180503
+ 9.4.24.v20191120
1.4.0
1.11.3
2.1.3
@@ -3180,7 +3221,7 @@ org.eclipse.jdt.apt.processorOptions/defaultOverwrite=true
5.2.0
1.11.3
3.0.2
- 1.2.51
+ 1.3.31
1.17.2
1.2
1.2.3
@@ -3191,11 +3232,11 @@ org.eclipse.jdt.apt.processorOptions/defaultOverwrite=true
3.8.0
${mongo-java-driver.version}
1.3.2
- 5.1.42
+ 5.1.47
3.4.0.52.4
3.4.0.52
3.3.2
- 4.1.27.Final
+ 4.1.43.Final
1.9.9
2.3.1
2.4.0
@@ -3214,16 +3255,17 @@ org.eclipse.jdt.apt.processorOptions/defaultOverwrite=true
3.1.0
1.7.25
1.7.25
- 1.19
+ 1.25
2.12.3
1.0.36
3.0.0
3.17.1
1.5.20
- 3.0.9.RELEASE
- 2.0.9.Final
+ 3.0.10.RELEASE
+ 2.0.28.Final
2.1
2.4.8
+ 0.12.1
**
@@ -3233,7 +3275,7 @@ org.eclipse.jdt.apt.processorOptions/defaultOverwrite=true
3.11.2
- 4.1.4
+ 4.2.1
2.0.4
@@ -3245,7 +3287,7 @@ org.eclipse.jdt.apt.processorOptions/defaultOverwrite=true
3.5.0
2.5.9
1.1.1
- 3.1.6
+ 4.6.18
0.0.8
2.2
1.2.0
@@ -3273,7 +3315,7 @@ org.eclipse.jdt.apt.processorOptions/defaultOverwrite=true
3.1.0
2.1.1
0.4.13
- 0.9.13
+ 0.9.18
1.2.1
1.6.0
${jacoco.version}