DATAREDIS-423 - Polishing.

Extend documentation. Reformat JavaDoc. Adjust test method names.

Original pull request: #197.
This commit is contained in:
Mark Paluch
2016-05-13 12:01:54 +02:00
parent 568e41f8dd
commit d097a64bc6
4 changed files with 79 additions and 12 deletions

View File

@@ -363,9 +363,9 @@ Hash mappers are converters to map objects to a `Map<K, V>` and back. `HashMappe
Multiple implementations are available out of the box:
1. `BeanUtilsHashMapper` using Spring's http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/beans/BeanUtils.html[BeanUtils]
2. `ObjectHashMapper` using <<redis.repositories.mapping>>
3. `Jackson2HashMapper` using https://github.com/FasterXML/jackson[FasterXML Jackson].
1. `BeanUtilsHashMapper` using Spring's http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/beans/BeanUtils.html[BeanUtils].
2. `ObjectHashMapper` using <<redis.repositories.mapping>>.
3. <<redis.hashmappers.jackson2,`Jackson2HashMapper`>> using https://github.com/FasterXML/jackson[FasterXML Jackson].
[source,java]
----
@@ -397,6 +397,67 @@ public class HashMapping {
}
----
[[redis.hashmappers.jackson2]]
=== Jackson2HashMapper
`Jackson2HashMapper` provides Redis Hash mapping for domain objects using https://github.com/FasterXML/jackson[FasterXML Jackson].
`Jackson2HashMapper` can map data map top-level properties as Hash field names and optionally flatten the structure.
Simple types map to simple values. Complex types (nested objects, collections, maps) are represented as nested JSON.
Flattening creates individual hash entries for all nested properties and resolves complex types into simple types, as far as possible.
[source,java]
----
public class Person {
String firstname;
String lastname;
Address address;
}
public class Address {
String city;
String country;
}
----
.Normal Mapping
[width="80%",cols="<1,<2",options="header"]
|====
|Hash Field
|Value
|firstname
|`Jon`
|lastname
|`Snow`
|address
|`{ "city" : "Castle Black", "country" : "The North" }`
|====
.Flat Mapping
[width="80%",cols="<1,<2",options="header"]
|====
|Hash Field
|Value
|firstname
|`Jon`
|lastname
|`Snow`
|address.city
|`Castle Black`
|address.country
|`The North`
|====
NOTE: Flattening requires all property names to not interfere with the JSON path. Using dots or brackets in map keys
or as property names is not supported using flattening. The resulting hash cannot be mapped back into an Object.
:leveloffset: 2
include::{referenceDir}/redis-messaging.adoc[]

View File

@@ -43,8 +43,13 @@ import com.fasterxml.jackson.databind.SerializationFeature;
/**
* {@link ObjectMapper} based {@link HashMapper} implementation that allows flattening. Given an entity {@code Person}
* with an {@code Address} like below the flattening will create individual hash entries for all nested properties.
* with an {@code Address} like below the flattening will create individual hash entries for all nested properties and
* resolve complex types into simple types, as far as possible.
* <p>
* Flattening requires all property names to not interfere with JSON paths. Using dots or brackets in map keys or as
* property names is not supported using flattening. The resulting hash cannot be mapped back into an Object.
*
* <strong>Example</strong>
* <pre>
* <code>
* class Person {
@@ -60,24 +65,25 @@ import com.fasterxml.jackson.databind.SerializationFeature;
* </code>
* </pre>
*
* <pre>
* <strong>Normal</strong><br />
* <strong>Normal</strong>
* <table>
* <tr><th>Hash field</th><th>Value<th></tr>
* <tr><td>firstname</td><td>Jon<td></tr>
* <tr><td>lastname</td><td>Snow<td></tr>
* <tr><td>address</td><td>{ city : Castle Black, country : The North }<td></tr>
* <tr><td>address</td><td>{ "city" : "Castle Black", "country" : "The North" }<td></tr>
* </table>
*
* <strong>Flat</strong>: <br />
* <br />
* <strong>Flat</strong>:
* <table>
* <tr><th>Hash field</th><th>Value<th></tr>
*   <tr><td>firstname</td><td>Jon<td></tr>
* <tr><td>lastname</td><td>Snow<td></tr>
* <tr><td>address.city</td><td>Castle Black<td></tr>
* <tr><td>address.country</td><td>The North<td></tr>
* </table>
* </pre>
*
* @author Christoph Strobl
* @author Mark Paluch
* @since 1.8
*/
public class Jackson2HashMapper implements HashMapper<Object, String, Object> {

View File

@@ -82,7 +82,7 @@ public class Jackson2HashMapperTests {
* @see DATAREDIS-423
*/
@Test
public void shouldWriteReadHashCorrtectly() {
public void shouldWriteReadHashCorrectly() {
Person jon = new Person("jon", "snow", 19);
Address adr = new Address();

View File

@@ -73,7 +73,7 @@ public class Jackson2HashMapperUnitTests extends AbstractHashMapperTest {
* @see DATAREDIS-423
*/
@Test
public void shouldMapTypledListOfComplexType() {
public void shouldMapTypedListOfComplexType() {
WithList source = new WithList();