|  | 
|  | 1 | +/* | 
|  | 2 | + * (c) Copyright 2025 Palantir Technologies Inc. All rights reserved. | 
|  | 3 | + * | 
|  | 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | 
|  | 5 | + * you may not use this file except in compliance with the License. | 
|  | 6 | + * You may obtain a copy of the License at | 
|  | 7 | + * | 
|  | 8 | + *     http://www.apache.org/licenses/LICENSE-2.0 | 
|  | 9 | + * | 
|  | 10 | + * Unless required by applicable law or agreed to in writing, software | 
|  | 11 | + * distributed under the License is distributed on an "AS IS" BASIS, | 
|  | 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
|  | 13 | + * See the License for the specific language governing permissions and | 
|  | 14 | + * limitations under the License. | 
|  | 15 | + */ | 
|  | 16 | + | 
|  | 17 | +package com.palantir.conjure.java.api.errors; | 
|  | 18 | + | 
|  | 19 | +/** | 
|  | 20 | + * Base class for serializable Conjure errors with generic parameter type support. | 
|  | 21 | + * <p> | 
|  | 22 | + * This abstract class represents serialized Conjure errors. It supports generic parameter types to allow for | 
|  | 23 | + * deserialization of custom error parameters. | 
|  | 24 | + * <p> | 
|  | 25 | + * Usage example where {@code CustomErrorParameters} is a user-defined class representing the error parameters: | 
|  | 26 | + * <pre> | 
|  | 27 | + * {@code | 
|  | 28 | + * class CustomError extends AbstractSerializableError<CustomErrorParameters> { | 
|  | 29 | + *     @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) | 
|  | 30 | + *     CustomError( | 
|  | 31 | + *         @JsonProperty("errorCode") String errorCode, | 
|  | 32 | + *         @JsonProperty("errorName") String errorName, | 
|  | 33 | + *         @JsonProperty("errorInstanceId") String errorInstanceId, | 
|  | 34 | + *         @JsonProperty("parameters") CustomErrorParameters parameters) { | 
|  | 35 | + *         super(errorCode, errorName, errorInstanceId, parameters); | 
|  | 36 | + *     } | 
|  | 37 | + * } | 
|  | 38 | + * } | 
|  | 39 | + * </pre> | 
|  | 40 | + */ | 
|  | 41 | +public abstract class AbstractSerializableError<T> { | 
|  | 42 | +    private final String errorCode; | 
|  | 43 | +    private final String errorName; | 
|  | 44 | +    private final String errorInstanceId; | 
|  | 45 | +    private final T parameters; | 
|  | 46 | + | 
|  | 47 | +    public final String errorCode() { | 
|  | 48 | +        return errorCode; | 
|  | 49 | +    } | 
|  | 50 | + | 
|  | 51 | +    public final String errorName() { | 
|  | 52 | +        return errorName; | 
|  | 53 | +    } | 
|  | 54 | + | 
|  | 55 | +    public final String errorInstanceId() { | 
|  | 56 | +        return errorInstanceId; | 
|  | 57 | +    } | 
|  | 58 | + | 
|  | 59 | +    public final T parameters() { | 
|  | 60 | +        return parameters; | 
|  | 61 | +    } | 
|  | 62 | + | 
|  | 63 | +    protected AbstractSerializableError(String errorCode, String errorName, String errorInstanceId, T parameters) { | 
|  | 64 | +        this.errorCode = errorCode; | 
|  | 65 | +        this.errorName = errorName; | 
|  | 66 | +        this.errorInstanceId = errorInstanceId; | 
|  | 67 | +        this.parameters = parameters; | 
|  | 68 | +    } | 
|  | 69 | +} | 
0 commit comments