Skip to content

Commit

Permalink
Minor code improvements.
Browse files Browse the repository at this point in the history
  • Loading branch information
ledsoft committed Jul 19, 2020
1 parent ff3d820 commit 2720802
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 14 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@

Java Binding for JSON-LD (JB4JSON-LD) is a simple library for serialization of Java objects into JSON-LD and vice versa.

Note that this is the core, abstract implementation. For actual usage, a binding like
[https://github.com/kbss-cvut/jb4jsonld-jackson](https://github.com/kbss-cvut/jb4jsonld-jackson)
Note that this is the core, abstract implementation. For actual usage, a binding like [https://github.com/kbss-cvut/jb4jsonld-jackson](https://github.com/kbss-cvut/jb4jsonld-jackson)
has to be used.

More information can be found at [https://kbss.felk.cvut.cz/web/kbss/jb4json-ld](https://kbss.felk.cvut.cz/web/kbss/jb4json-ld).
Expand Down
11 changes: 6 additions & 5 deletions src/main/java/cz/cvut/kbss/jsonld/common/BeanClassProcessor.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/**
* Copyright (C) 2020 Czech Technical University in Prague
*
* <p>
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any
* later version.
*
* <p>
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
Expand All @@ -18,6 +18,7 @@
import cz.cvut.kbss.jsonld.exception.TargetTypeException;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.net.URI;
Expand Down Expand Up @@ -77,8 +78,8 @@ public static void setFieldValue(Field field, Object instance, Object value) {
*/
public static <T> T createInstance(Class<T> cls) {
try {
return cls.newInstance();
} catch (InstantiationException | IllegalAccessException e) {
return cls.getDeclaredConstructor().newInstance();
} catch (NoSuchMethodException | InstantiationException | InvocationTargetException | IllegalAccessException e) {
throw new BeanProcessingException("Class " + cls + " is missing a public no-arg constructor.", e);
}
}
Expand Down Expand Up @@ -210,7 +211,7 @@ public static Class<?> getMapGenericValueType(Field field) {
final Type actualType = valueType.getActualTypeArguments()[0];
if (Class.class.isAssignableFrom(actualType.getClass())) {
// For Map<?, Collection<String>>
return Class.class.cast(actualType);
return (Class) actualType;
}
// For Map<?, Collection<?>>
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

class JsonLdPropertyAccessResolverTest {

private JsonLdPropertyAccessResolver sut = new JsonLdPropertyAccessResolver();
private final JsonLdPropertyAccessResolver sut = new JsonLdPropertyAccessResolver();

@ParameterizedTest
@CsvSource({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class NodeReferenceContextTest {

@BeforeEach
void setUp() {
MockitoAnnotations.initMocks(this);
MockitoAnnotations.openMocks(this);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class PropertiesFieldSerializerTest {

private Field field;

private FieldSerializer serializer = new PropertiesFieldSerializer();
private final FieldSerializer serializer = new PropertiesFieldSerializer();

@BeforeEach
void setUp() throws Exception {
Expand Down Expand Up @@ -143,4 +143,4 @@ void serializeFieldSerializesTypedPropertiesToCorrectTargetTypes() {
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ public abstract class AbstractNodeTest {
JsonGenerator serializerMock;

public void setUp() {
MockitoAnnotations.initMocks(this);
MockitoAnnotations.openMocks(this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class ObjectGraphTraverserTest {

@BeforeEach
void setUp() {
MockitoAnnotations.initMocks(this);
MockitoAnnotations.openMocks(this);
this.traverser = new ObjectGraphTraverser();
traverser.addVisitor(visitor);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

public class BufferedJsonGenerator implements JsonGenerator {

private StringBuilder buffer = new StringBuilder();
private final StringBuilder buffer = new StringBuilder();

private boolean firstElement = true;
private boolean firstAttribute = true;
Expand Down

0 comments on commit 2720802

Please sign in to comment.