Skip to content

Commit

Permalink
v2.7
Browse files Browse the repository at this point in the history
  • Loading branch information
oleg-cherednik authored Nov 3, 2023
1 parent e13471a commit 2045cea
Show file tree
Hide file tree
Showing 49 changed files with 442 additions and 264 deletions.
37 changes: 33 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,14 @@
## Gradle

```groovy
compile 'ru.oleg-cherednik.jackson:jackson-utils:2.6'
implementation 'ru.oleg-cherednik.jackson:jackson-utils:2.7'
```
_Optional dependencies (e.g. Jackson of version __2.15.3__):_
```groovy
implementation 'com.fasterxml.jackson.module:jackson-module-afterburner:2.15.3'
implementation 'com.fasterxml.jackson.module:jackson-module-parameter-names:2.15.3'
implementation 'com.fasterxml.jackson.datatype:jackson-datatype-jdk8:2.15.3'
implementation 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.15.3'
```

## Maven
Expand All @@ -40,12 +47,34 @@ compile 'ru.oleg-cherednik.jackson:jackson-utils:2.6'
<dependency>
<groupId>ru.oleg-cherednik.jackson</groupId>
<artifactId>jackson-utils</artifactId>
<version>2.6</version>
<version>2.7</version>
</dependency>
```
_Optional dependencies (e.g. Jackson of version __2.15.3__):_
```xml
<dependency>
<groupId>com.fasterxml.jackson.module</groupId>
<artifactId>jackson-module-afterburner</artifactId>
<version>2.15.3</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.module</groupId>
<artifactId>jackson-module-parameter-names</artifactId>
<version>2.15.3</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jdk8</artifactId>
<version>2.15.3</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
<version>2.15.3</version>
</dependency>
```

**Note:** `jackson-utils` does not contain dependency to the specific `Jackson Project`
version, so you have to add it additionally:
version, so you have to add any version additionally

## Usage

Expand Down
27 changes: 18 additions & 9 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ plugins {
id 'jacoco'
id 'java-library'
id 'org.cadixdev.licenser' version '0.6.1'
id 'io.franzbecker.gradle-lombok' version '4.0.0'

id 'signing'
id 'maven-publish'
Expand All @@ -21,15 +22,19 @@ repositories {
}

group 'ru.oleg-cherednik.jackson'
version '2.6'
version '2.7'

sourceCompatibility = '1.8'
targetCompatibility = '1.8'

tasks.withType(JavaCompile) {
tasks.withType(JavaCompile).configureEach {
options.encoding = 'UTF-8'
}

tasks.withType(JavaCompile).configureEach {
options.compilerArgs += ['-Xlint:unchecked']
}

configurations {
jar.archiveFileName = "${rootProject.name}-${version}.jar"
}
Expand All @@ -42,20 +47,22 @@ dependencies {

implementation "ru.oleg-cherednik.utils.reflection:reflection-utils:${property('reflection-utils.version')}"

testImplementation('org.testng:testng:7.5') {
annotationProcessor 'org.projectlombok:lombok:1.18.24'

testImplementation('org.testng:testng:7.8.0') {
exclude group: 'junit', module: 'junit'
exclude group: 'org.apache.ant', module: 'ant'
}

testImplementation "com.fasterxml.jackson.core:jackson-databind:${property('jackson.version')}"
testImplementation "com.fasterxml.jackson.module:jackson-module-afterburner:${property('jackson.version')}"
testImplementation "com.fasterxml.jackson.module:jackson-module-parameter-names:2.13.2"
testImplementation "com.fasterxml.jackson.module:jackson-module-parameter-names:${property('jackson.version')}"
testImplementation "com.fasterxml.jackson.datatype:jackson-datatype-jdk8:${property('jackson.version')}"
testImplementation "com.fasterxml.jackson.datatype:jackson-datatype-jsr310:${property('jackson.version')}"

testImplementation 'org.assertj:assertj-core:3.22.0'
testImplementation 'commons-io:commons-io:2.11.0'
testImplementation 'org.mockito:mockito-core:4.5.1'
testImplementation 'org.assertj:assertj-core:3.24.2'
testImplementation 'commons-io:commons-io:2.15.0'
testImplementation 'org.mockito:mockito-core:5.6.0'

testImplementation("org.springframework.boot:spring-boot-starter-web:${property('spring-boot.version')}") {
exclude group: 'org.junit.jupiter'
Expand All @@ -68,12 +75,14 @@ dependencies {
exclude group: 'org.junit.vintage'
exclude group: 'org.junit.jupiter'
}

testAnnotationProcessor 'org.projectlombok:lombok:1.18.24'
}

jacocoTestReport {
reports {
xml.enabled true
html.enabled true
xml.required = true
html.required = true
}
}

Expand Down
8 changes: 6 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
jackson.version=2.13.2
# https://docs.gradle.org/current/userguide/performance.html
org.gradle.parallel=true
org.gradle.daemon=true
org.gradle.caching=false
jackson.version=2.15.3
reflection-utils.version=1.0
spring-boot.version=2.6.7
spring-boot.version=2.7.17
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
* specific language governing permissions and limitations
* under the License.
*/
package ru.olegcherednik.jackson.utils;
package ru.olegcherednik.jackson_utils;

import lombok.RequiredArgsConstructor;

import java.io.IOException;
import java.io.InputStream;
Expand All @@ -26,14 +28,11 @@
* @author Oleg Cherednik
* @since 18.02.2022
*/
@RequiredArgsConstructor
final class ByteBufferInputStream extends InputStream {

private final ByteBuffer buf;

public ByteBufferInputStream(ByteBuffer buf) {
this.buf = buf;
}

@Override
public int read() throws IOException {
return buf.hasRemaining() ? buf.get() & 0xFF : -1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
package ru.olegcherednik.jackson.utils;
package ru.olegcherednik.jackson_utils;

import java.util.Optional;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
package ru.olegcherednik.jackson.utils;
package ru.olegcherednik.jackson_utils;

import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonInclude;
Expand All @@ -28,14 +28,16 @@
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import com.fasterxml.jackson.module.afterburner.AfterburnerModule;
import com.fasterxml.jackson.module.paramnames.ParameterNamesModule;
import ru.olegcherednik.jackson.utils.enumid.EnumIdModule;
import ru.olegcherednik.jackson.utils.serializers.JacksonUtilsDateSerializer;
import ru.olegcherednik.jackson.utils.serializers.JacksonUtilsInstantSerializer;
import ru.olegcherednik.jackson.utils.serializers.JacksonUtilsLocalDateTimeSerializer;
import ru.olegcherednik.jackson.utils.serializers.JacksonUtilsLocalTimeSerializer;
import ru.olegcherednik.jackson.utils.serializers.JacksonUtilsOffsetDateTimeSerializer;
import ru.olegcherednik.jackson.utils.serializers.JacksonUtilsOffsetTimeSerializer;
import ru.olegcherednik.jackson.utils.serializers.JacksonUtilsZonedDateTimeSerializer;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import ru.olegcherednik.jackson_utils.enumid.EnumIdModule;
import ru.olegcherednik.jackson_utils.serializers.JacksonUtilsDateSerializer;
import ru.olegcherednik.jackson_utils.serializers.JacksonUtilsInstantSerializer;
import ru.olegcherednik.jackson_utils.serializers.JacksonUtilsLocalDateTimeSerializer;
import ru.olegcherednik.jackson_utils.serializers.JacksonUtilsLocalTimeSerializer;
import ru.olegcherednik.jackson_utils.serializers.JacksonUtilsOffsetDateTimeSerializer;
import ru.olegcherednik.jackson_utils.serializers.JacksonUtilsOffsetTimeSerializer;
import ru.olegcherednik.jackson_utils.serializers.JacksonUtilsZonedDateTimeSerializer;

import java.time.Instant;
import java.time.LocalDateTime;
Expand Down Expand Up @@ -129,14 +131,12 @@ protected ObjectMapper registerModule(ObjectMapper mapper) {
.addKeySerializer(Date.class, dateSerializer));
}

@NoArgsConstructor(access = AccessLevel.PRIVATE)
public static class Builder {

private UnaryOperator<ZoneId> zoneModifier = ZONE_MODIFIER_TO_UTC;
private boolean useMilliseconds = true;

protected Builder() {
}

public Builder zone(ZoneId zone) {
return zoneModifier(z -> zone);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@
* specific language governing permissions and limitations
* under the License.
*/
package ru.olegcherednik.jackson.utils;
package ru.olegcherednik.jackson_utils;

import lombok.AccessLevel;
import lombok.NoArgsConstructor;

import java.io.InputStream;
import java.io.OutputStream;
Expand All @@ -31,6 +34,7 @@
* @author Oleg Cherednik
* @since 19.11.2014
*/
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class JacksonUtils {

private static final ObjectMapperDecorator DELEGATE = new ObjectMapperDecorator(JacksonUtilsHelper::mapper);
Expand Down Expand Up @@ -204,7 +208,4 @@ public static <V> Map<String, Object> convertToMap(V obj) {
return print().convertToMap(obj);
}

private JacksonUtils() {
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
package ru.olegcherednik.jackson.utils;
package ru.olegcherednik.jackson_utils;

/**
* @author Oleg Cherednik
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@
* specific language governing permissions and limitations
* under the License.
*/
package ru.olegcherednik.jackson.utils;
package ru.olegcherednik.jackson_utils;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;

import java.util.Optional;
import java.util.function.Supplier;
Expand All @@ -28,6 +30,7 @@
* @author Oleg Cherednik
* @since 19.11.2014
*/
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class JacksonUtilsHelper {

public static final Supplier<ObjectMapper> DEFAULT_BUILDER = JacksonObjectMapperSupplier.builder().build();
Expand Down Expand Up @@ -74,15 +77,12 @@ public static ObjectMapperDecorator createMapperDecorator(Supplier<ObjectMapper>
public static synchronized void setMapperBuilder(Supplier<ObjectMapper> mapperSupplier) {
mapperSupplier = Optional.ofNullable(mapperSupplier).orElse(DEFAULT_BUILDER);

if (mapperSupplier == JacksonUtilsHelper.mapperBuilder)
if (mapperSupplier == mapperBuilder)
return;

JacksonUtilsHelper.mapperBuilder = mapperSupplier;
mapperBuilder = mapperSupplier;
mapper = createMapper();
prettyPrintMapper = createPrettyPrintMapper();
}

private JacksonUtilsHelper() {
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@
* specific language governing permissions and limitations
* under the License.
*/
package ru.olegcherednik.jackson.utils;
package ru.olegcherednik.jackson_utils;

import com.fasterxml.jackson.databind.MappingIterator;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectReader;
import com.fasterxml.jackson.databind.type.MapType;
import ru.olegcherednik.jackson.utils.types.ListMapTypeReference;
import lombok.RequiredArgsConstructor;
import ru.olegcherednik.jackson_utils.types.ListMapTypeReference;

import java.io.InputStream;
import java.io.OutputStream;
Expand All @@ -43,6 +44,7 @@
* @author Oleg Cherednik
* @since 02.01.2021
*/
@RequiredArgsConstructor
public class ObjectMapperDecorator {

protected final Supplier<ObjectMapper> supplier;
Expand All @@ -51,10 +53,6 @@ public ObjectMapperDecorator(ObjectMapper mapper) {
this(() -> mapper);
}

public ObjectMapperDecorator(Supplier<ObjectMapper> supplier) {
this.supplier = supplier;
}

// ---------- read String----------

public <V> V readValue(String json, Class<V> valueClass) {
Expand Down Expand Up @@ -391,15 +389,15 @@ public <V> Map<String, Object> convertToMap(V obj) {
private static <V> V withRuntimeException(Callable<V> task) {
try {
return task.call();
} catch(Exception e) {
} catch (Exception e) {
throw new JacksonUtilsException(e);
}
}

private static <V> V withInputStream(ByteBuffer buf, Function<InputStream, V> task) {
try (InputStream in = new ByteBufferInputStream(buf)) {
return task.apply(in);
} catch(Exception e) {
} catch (Exception e) {
throw new JacksonUtilsException(e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
* specific language governing permissions and limitations
* under the License.
*/
package ru.olegcherednik.jackson.utils.enumid;
package ru.olegcherednik.jackson_utils.enumid;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.ser.BeanPropertyWriter;
import ru.olegcherednik.jackson.utils.EnumId;
import ru.olegcherednik.jackson_utils.EnumId;

/**
* @author Oleg Cherednik
Expand Down
Loading

0 comments on commit 2045cea

Please sign in to comment.