/
JsonParseException.java
executable file
·82 lines (66 loc) · 2.43 KB
/
JsonParseException.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/*
* Copyright (c) 2017-2018 Bosch Software Innovations GmbH.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/org/documents/epl-2.0/index.php
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.eclipse.ditto.json;
import java.net.URI;
import javax.annotation.Nullable;
import javax.annotation.concurrent.NotThreadSafe;
/**
* Thrown if JSON could not be parsed because it was in an invalid format.
*/
public final class JsonParseException extends JsonRuntimeException {
/**
* Error code of this exception.
*/
public static final String ERROR_CODE = "json.invalid";
private static final String DEFAULT_DESCRIPTION =
"Check if the JSON was valid (e.g. on https://jsonlint.com) and if it was in required format.";
private static final long serialVersionUID = -7585793723086474449L;
private JsonParseException(@Nullable final String message,
@Nullable final String description,
@Nullable final Throwable cause,
@Nullable final URI href) {
super(ERROR_CODE, message, description, cause, href);
}
/**
* Constructs a new {@code JsonParseException} with the specified message.
*
* @param message the detail message.
*/
public JsonParseException(@Nullable final String message) {
this(message, DEFAULT_DESCRIPTION, null, null);
}
/**
* Returns a builder for fluently creating instances of {@code JsonParseException}s..
*
* @return a new builder for JsonParseException objects.
*/
public static Builder newBuilder() {
return new Builder();
}
/**
* A mutable builder for a {@code JsonParseException}.
*/
@NotThreadSafe
public static final class Builder extends AbstractJsonExceptionBuilder<JsonParseException> {
private Builder() {
super(ERROR_CODE);
description(DEFAULT_DESCRIPTION);
}
@Override
protected JsonParseException doBuild(final String errorCode,
@Nullable final String message,
@Nullable final String description,
@Nullable final Throwable cause,
@Nullable final URI href) {
return new JsonParseException(message, description, cause, href);
}
}
}