Skip to content

Commit

Permalink
Adds javadoc and exception handling in GlobalErrorRegistry
Browse files Browse the repository at this point in the history
Signed-off-by: Klem Yannic (INST/ECS1) <Yannic.Klem@bosch-si.com>
  • Loading branch information
Yannic92 committed Feb 1, 2019
1 parent 50e8154 commit 8666897
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,22 @@

import org.atteo.classindex.IndexAnnotated;

/**
* This annotated marks a class as deserializable from Json when calling the specified
* {@link JsonParsableException#method()} with {@link org.eclipse.ditto.json.JsonObject} as first
* and {@link org.eclipse.ditto.model.base.headers.DittoHeaders} as second argument.
* The {@link JsonParsableException#errorCode()} is used as identifier of this exception.
*/
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@IndexAnnotated
public @interface JsonParsableException {

/**
* Used as identifier of the exception.
*
* @return the error code.
*/
String errorCode();

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.concurrent.Immutable;
Expand Down Expand Up @@ -59,6 +57,11 @@ protected String resolveType(final JsonObject jsonObject) {
.build());
}

/**
* Gets an instance of {@link GlobalErrorRegistry}.
*
* @return the instance of {@link GlobalErrorRegistry}.
*/
public static GlobalErrorRegistry getInstance() {
return instance;
}
Expand Down Expand Up @@ -133,7 +136,10 @@ private JsonParsableExceptionRegistry() {
appendMethodToParseStrategies(errorCode, method);

} catch (NoSuchMethodException e) {
// TODO: Log warning or throw an exception?
final String message = String.format("Could not create deserializing strategy for '%s'.",
parsableException.getName());

throw new Error(message, e);
}
});
}
Expand Down

0 comments on commit 8666897

Please sign in to comment.