Skip to content

Commit

Permalink
#163: added build-in JSON support
Browse files Browse the repository at this point in the history
  • Loading branch information
hohwille committed Jun 30, 2016
1 parent de993bd commit 71a1f53
Show file tree
Hide file tree
Showing 82 changed files with 1,569 additions and 137 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ public interface EnumDefinition<TYPE, CATEGORY> extends SimpleDatatype<String> {
* <b>ATTENTION:</b><br>
* A {@link EnumDefinition} may be used with or without allowing a {@code null} value. Therefore, this
* {@link Formatter} should be able to properly format {@code null} (see
* {@link net.sf.mmm.util.lang.base.AbstractFormatter#formatNull()}). E.g. a {@link Boolean} option in a search form
* may be optional and displayed as "any".
* {@link net.sf.mmm.util.lang.base.AbstractFormatter}{@code .formatNull()}). E.g. a {@link Boolean} option in a
* search form may be optional and displayed as "any".
*
* @return the {@link Formatter}.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* configured in {@code org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.setPackagesToScan}.</li>
* </ol>
*
* For an example how to implement such a converter see e.g. {@link VersionIdentifierAttributeConverter}.
* For an example how to implement such a converter see e.g. {@code VersionIdentifierAttributeConverter}.
*
* <br/>
* <b>ATTENTION:</b><br/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@

import net.sf.mmm.util.exception.api.NlsNullPointerException;
import net.sf.mmm.util.exception.api.ObjectMismatchException;
import net.sf.mmm.util.exception.api.ValueOutOfRangeException;
import net.sf.mmm.util.lang.api.DatatypeDescriptor;
import net.sf.mmm.util.lang.api.DatatypeSegmentDescriptor;
import net.sf.mmm.util.reflect.api.InstantiationFailedException;
import net.sf.mmm.util.value.api.ValueOutOfRangeException;

/**
* This is the abstract base implementation of {@link DatatypeDescriptor}.
Expand Down Expand Up @@ -87,8 +87,8 @@ public T create(Object... segments) {
Integer.valueOf(this.segmentDescriptorList.size()), "segments.length");
} else if (segments.length < this.requiredSegmentCount) {
throw new ValueOutOfRangeException(Integer.valueOf(segments.length),
(Number) Integer.valueOf(this.requiredSegmentCount),
Integer.valueOf(this.segmentDescriptorList.size()), "segments.length");
(Number) Integer.valueOf(this.requiredSegmentCount), Integer.valueOf(this.segmentDescriptorList.size()),
"segments.length");
}
}
return doCreate(segments);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
package net.sf.mmm.util.lang.base.datatype.descriptor;

import net.sf.mmm.util.exception.api.IllegalCaseException;
import net.sf.mmm.util.exception.api.WrongValueTypeException;
import net.sf.mmm.util.lang.api.StringUtil;
import net.sf.mmm.util.value.api.WrongValueTypeException;

/**
* This is the implementation of {@link net.sf.mmm.util.lang.api.DatatypeDescriptor} for a {@link Enum}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
* <tr>
* <td>ERR_</td>
* <td>Text for an exception message.</td>
* <td>{@code ERR_VALUE_NOT_SET = "The value \"{value}\" is not set!"}</td>
* <td><code>ERR_VALUE_NOT_SET = "The value \"{value}\" is not set!"</code></td>
* </tr>
* <tr>
* <td>MSG_</td>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
import net.sf.mmm.test.ExceptionHelper;
import net.sf.mmm.util.component.impl.SpringContainerPool;
import net.sf.mmm.util.date.base.Iso8601UtilImpl;
import net.sf.mmm.util.exception.api.ValueOutOfRangeException;
import net.sf.mmm.util.lang.api.CompareOperator;
import net.sf.mmm.util.lang.api.DatatypeDescriptor;
import net.sf.mmm.util.lang.api.DatatypeDescriptorManager;
import net.sf.mmm.util.lang.api.DatatypeSegmentDescriptor;
import net.sf.mmm.util.reflect.api.InstantiationFailedException;
import net.sf.mmm.util.value.api.ValueOutOfRangeException;

/**
* This is the test-case for {@link DatatypeDescriptorManager} or technically
Expand All @@ -34,8 +34,8 @@ public DatatypeDescriptorManager getDatatypeDescriptorManager() {
return SpringContainerPool.getInstance().get(DatatypeDescriptorManager.class);
}

private <T> void checkSegment(DatatypeSegmentDescriptor<T, ?> segment, String name, Class<?> type,
boolean optional, T instance, Object value) {
private <T> void checkSegment(DatatypeSegmentDescriptor<T, ?> segment, String name, Class<?> type, boolean optional,
T instance, Object value) {

assertNotNull(segment);
assertEquals(name, segment.getName());
Expand Down Expand Up @@ -107,8 +107,7 @@ public void testDate() {
descriptor.create(year, month, day, hour, minute));
assertEquals(Iso8601UtilImpl.getInstance().parseDate("2013-12-31T23:00:00"),
descriptor.create(year, month, day, hour));
assertEquals(Iso8601UtilImpl.getInstance().parseDate("2013-12-31T00:00:00"),
descriptor.create(year, month, day));
assertEquals(Iso8601UtilImpl.getInstance().parseDate("2013-12-31T00:00:00"), descriptor.create(year, month, day));

try {
descriptor.create(year, month);
Expand Down
13 changes: 13 additions & 0 deletions json/README.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
= Mature Modular Meta-framework (mmm)

image:https://raw.github.com/m-m-m/mmm/master/src/site/resources/images/logo.png[logo]

*Welcome to the wonderful world of http://m-m-m.sourceforge.net/index.html[mmm]!*

== mmm-util-property

This module is part of link:../../..#mmm-util[mmm-util] and brings extended JSON support including:

* https://m-m-m.github.io/maven/apidocs/net/sf/mmm/util/json/api/JsonUtil.html[JsonUtil] for advanced generic JSON support based on JSON-P.
* https://m-m-m.github.io/maven/apidocs/net/sf/mmm/util/json/api/JsonSupport.html[JsonSupport] interface as API for objects with build-in JSON support.
* https://m-m-m.github.io/maven/apidocs/[and much more... ]
57 changes: 57 additions & 0 deletions json/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?xml version='1.0' encoding='UTF-8'?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>net.sf.m-m-m</groupId>
<artifactId>mmm-util-modules</artifactId>
<version>dev-SNAPSHOT</version>
<relativePath>../modules/pom.xml</relativePath>
</parent>
<artifactId>mmm-util-json</artifactId>
<version>${net.sf.mmm.util8.version}</version>
<packaging>jar</packaging>
<name>${project.artifactId}</name>
<description>This project provides advanced JSON support based on JSON-P.</description>

<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>mmm-util-core</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>javax.json</groupId>
<artifactId>javax.json-api</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>javax.json</artifactId>
<version>1.0.4</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>mmm-util-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
39 changes: 39 additions & 0 deletions json/src/main/java/net/sf/mmm/util/json/api/JsonSupport.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/* Copyright (c) The m-m-m Team, Licensed under the Apache License, Version 2.0
* http://www.apache.org/licenses/LICENSE-2.0 */
package net.sf.mmm.util.json.api;

import javax.json.stream.JsonGenerator;
import javax.json.stream.JsonParser;

/**
* This is the interface for an object that supports to {@link #toJson(JsonGenerator) serialize itself to JSON}.
*
* @author hohwille
* @since 8.0.0
*/
public interface JsonSupport {

/** The JSON property name for the type information for polymorphic mapping of {@link #getClass()}. */
String PROPERTY_TYPE = "@type";

/**
* Serializes this object as JSON (JavaScript-Object-Notation).
*
* @see JsonHelper#toJson(JsonGenerator, String, Object)
*
* @param json the {@link JsonGenerator} where to write this object to. Has to be in
* {@link JsonGenerator#writeStartObject()} state.
*/
void toJson(JsonGenerator json);

/**
* Deserializes this object from JSON (JavaScript-Object-Notation). This operation is typically NOT symmetric to
* {@link #toJson(JsonGenerator)} - e.g. {@link #toJson(JsonGenerator)} might write a property with its value while
* {@link #fromJson(JsonParser)} may only deserialze the value as the parent object has to handle the property names
* that may appear in any order.
*
* @param json the {@link JsonParser} to read from.
*/
void fromJson(JsonParser json);

}
Loading

0 comments on commit 71a1f53

Please sign in to comment.