Skip to content

Commit e6d897b

Browse files
authored
Merge pull request #18 from JavaWebStack/dev
Release 1.0.4
2 parents aae4425 + a344c2d commit e6d897b

File tree

7 files changed

+39
-12
lines changed

7 files changed

+39
-12
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@ You can find the current docs on our [website](https://docs.javawebstack.org/fra
2222
<dependency>
2323
<groupId>org.javawebstack</groupId>
2424
<artifactId>abstract-data</artifactId>
25-
<version>1.0.3</version>
25+
<version>1.0.4</version>
2626
</dependency>
2727
```

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<properties>
88
<maven.compiler.source>8</maven.compiler.source>
99
<maven.compiler.target>8</maven.compiler.target>
10-
<buildVersion>1.0.3-SNAPSHOT</buildVersion>
10+
<buildVersion>1.0.4-SNAPSHOT</buildVersion>
1111
</properties>
1212

1313
<groupId>org.javawebstack</groupId>

src/main/java/org/javawebstack/abstractdata/AbstractArray.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import org.javawebstack.abstractdata.exception.AbstractCoercingException;
55

66
import java.util.*;
7+
import java.util.function.Consumer;
78
import java.util.function.Function;
89
import java.util.stream.Collector;
910
import java.util.stream.Stream;
@@ -319,6 +320,15 @@ public Map<String[], Object> toTree() {
319320
return object().toTree();
320321
}
321322

323+
public Map<String, Object> toTree(String keySeparator) {
324+
return object().toTree(keySeparator);
325+
}
326+
327+
public AbstractArray use(Consumer<AbstractArray> consumer) {
328+
consumer.accept(this);
329+
return this;
330+
}
331+
322332
public AbstractElement clone() {
323333
AbstractArray array = new AbstractArray();
324334
forEach(e -> array.add(e.clone()));

src/main/java/org/javawebstack/abstractdata/AbstractMapper.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
import org.javawebstack.abstractdata.mapper.Mapper;
44

5+
/**
6+
* @deprecated will be removed in the next release, replaced by org.javawebstack.abstractdata.mapper.Mapper
7+
*/
58
@Deprecated
69
public class AbstractMapper {
710

src/main/java/org/javawebstack/abstractdata/AbstractNull.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,22 @@ public boolean isNull() {
1919
}
2020

2121
public String string(boolean strict) throws AbstractCoercingException {
22-
if(strict)
23-
throw new AbstractCoercingException(Type.STRING, Type.NULL);
2422
return null;
2523
}
2624

2725
public Boolean bool(boolean strict) throws AbstractCoercingException {
28-
if(strict)
29-
throw new AbstractCoercingException(Type.STRING, Type.NULL);
3026
return null;
3127
}
3228

3329
public Number number(boolean strict) throws AbstractCoercingException {
34-
if(strict)
35-
throw new AbstractCoercingException(Type.STRING, Type.NULL);
30+
return null;
31+
}
32+
33+
public AbstractObject object(boolean strict) throws AbstractCoercingException {
34+
return null;
35+
}
36+
37+
public AbstractArray array(boolean strict) throws AbstractCoercingException {
3638
return null;
3739
}
3840

src/main/java/org/javawebstack/abstractdata/AbstractObject.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import java.util.Map;
1010
import java.util.Set;
1111
import java.util.function.BiConsumer;
12+
import java.util.function.Consumer;
1213
import java.util.function.Function;
1314
import java.util.stream.Collector;
1415
import java.util.stream.Stream;
@@ -233,6 +234,17 @@ public Map<String[], Object> toTree() {
233234
return tree;
234235
}
235236

237+
public Map<String, Object> toTree(String keySeparator) {
238+
Map<String, Object> tree = new HashMap<>();
239+
toTree().forEach((k, v) -> tree.put(String.join(keySeparator, k), v));
240+
return tree;
241+
}
242+
243+
public AbstractObject use(Consumer<AbstractObject> consumer) {
244+
consumer.accept(this);
245+
return this;
246+
}
247+
236248
public Set<String> keys() {
237249
return entries.keySet();
238250
}

src/main/java/org/javawebstack/abstractdata/mapper/DefaultMappers.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -273,14 +273,14 @@ public AbstractElement toAbstract(MapperContext context, Object value) throws Ma
273273
public Object fromAbstract(MapperContext context, AbstractElement element, Class<?> type) throws MapperException {
274274
try {
275275
DateFormat df = context.getAnnotation(DateFormat.class);
276-
java.text.DateFormat dateFormat = (df != null && df.value().length() > 0) ? new SimpleDateFormat(df.value()) : context.getMapper().getDateFormat();
277276
Date date;
278-
try {
277+
if(df != null && df.epoch()) {
279278
long time = element.number(context.getMapper().isStrict()).longValue();
280-
if(df != null && !df.millis())
279+
if(!df.millis())
281280
time *= 1000;
282281
date = new Date(time);
283-
} catch (AbstractCoercingException ex) {
282+
} else {
283+
java.text.DateFormat dateFormat = (df != null && df.value().length() > 0) ? new SimpleDateFormat(df.value()) : context.getMapper().getDateFormat();
284284
date = dateFormat.parse(element.string(context.getMapper().isStrict()));
285285
}
286286
if(type.equals(Date.class))

0 commit comments

Comments
 (0)