Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ You can find the current docs on our [website](https://docs.javawebstack.org/fra
<dependency>
<groupId>org.javawebstack</groupId>
<artifactId>abstract-data</artifactId>
<version>1.0.3</version>
<version>1.0.4</version>
</dependency>
```
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<buildVersion>1.0.3-SNAPSHOT</buildVersion>
<buildVersion>1.0.4-SNAPSHOT</buildVersion>
</properties>

<groupId>org.javawebstack</groupId>
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/org/javawebstack/abstractdata/AbstractArray.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.javawebstack.abstractdata.exception.AbstractCoercingException;

import java.util.*;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.stream.Collector;
import java.util.stream.Stream;
Expand Down Expand Up @@ -319,6 +320,15 @@ public Map<String[], Object> toTree() {
return object().toTree();
}

public Map<String, Object> toTree(String keySeparator) {
return object().toTree(keySeparator);
}

public AbstractArray use(Consumer<AbstractArray> consumer) {
consumer.accept(this);
return this;
}

public AbstractElement clone() {
AbstractArray array = new AbstractArray();
forEach(e -> array.add(e.clone()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import org.javawebstack.abstractdata.mapper.Mapper;

/**
* @deprecated will be removed in the next release, replaced by org.javawebstack.abstractdata.mapper.Mapper
*/
@Deprecated
public class AbstractMapper {

Expand Down
14 changes: 8 additions & 6 deletions src/main/java/org/javawebstack/abstractdata/AbstractNull.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,22 @@ public boolean isNull() {
}

public String string(boolean strict) throws AbstractCoercingException {
if(strict)
throw new AbstractCoercingException(Type.STRING, Type.NULL);
return null;
}

public Boolean bool(boolean strict) throws AbstractCoercingException {
if(strict)
throw new AbstractCoercingException(Type.STRING, Type.NULL);
return null;
}

public Number number(boolean strict) throws AbstractCoercingException {
if(strict)
throw new AbstractCoercingException(Type.STRING, Type.NULL);
return null;
}

public AbstractObject object(boolean strict) throws AbstractCoercingException {
return null;
}

public AbstractArray array(boolean strict) throws AbstractCoercingException {
return null;
}

Expand Down
12 changes: 12 additions & 0 deletions src/main/java/org/javawebstack/abstractdata/AbstractObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.util.Map;
import java.util.Set;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.stream.Collector;
import java.util.stream.Stream;
Expand Down Expand Up @@ -233,6 +234,17 @@ public Map<String[], Object> toTree() {
return tree;
}

public Map<String, Object> toTree(String keySeparator) {
Map<String, Object> tree = new HashMap<>();
toTree().forEach((k, v) -> tree.put(String.join(keySeparator, k), v));
return tree;
}

public AbstractObject use(Consumer<AbstractObject> consumer) {
consumer.accept(this);
return this;
}

public Set<String> keys() {
return entries.keySet();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,14 +273,14 @@ public AbstractElement toAbstract(MapperContext context, Object value) throws Ma
public Object fromAbstract(MapperContext context, AbstractElement element, Class<?> type) throws MapperException {
try {
DateFormat df = context.getAnnotation(DateFormat.class);
java.text.DateFormat dateFormat = (df != null && df.value().length() > 0) ? new SimpleDateFormat(df.value()) : context.getMapper().getDateFormat();
Date date;
try {
if(df != null && df.epoch()) {
long time = element.number(context.getMapper().isStrict()).longValue();
if(df != null && !df.millis())
if(!df.millis())
time *= 1000;
date = new Date(time);
} catch (AbstractCoercingException ex) {
} else {
java.text.DateFormat dateFormat = (df != null && df.value().length() > 0) ? new SimpleDateFormat(df.value()) : context.getMapper().getDateFormat();
date = dateFormat.parse(element.string(context.getMapper().isStrict()));
}
if(type.equals(Date.class))
Expand Down