-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
JDK 11 compile target reverted (#645)
JDK 11 compile target reverted Signed-off-by: David Kral <[email protected]>
- Loading branch information
Showing
5 changed files
with
163 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
src/main/java16/org/eclipse/yasson/internal/ClassMultiReleaseExtension.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
* Copyright (c) 2021, 2024 Oracle and/or its affiliates. All rights reserved. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0, | ||
* or the Eclipse Distribution License v. 1.0 which is available at | ||
* http://www.eclipse.org/org/documents/edl-v10.php. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause | ||
*/ | ||
|
||
package org.eclipse.yasson.internal; | ||
|
||
import java.lang.reflect.Constructor; | ||
import java.lang.reflect.Method; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
|
||
import jakarta.json.bind.JsonbException; | ||
import jakarta.json.bind.config.PropertyNamingStrategy; | ||
|
||
import org.eclipse.yasson.internal.model.JsonbCreator; | ||
import org.eclipse.yasson.internal.model.Property; | ||
import org.eclipse.yasson.internal.properties.MessageKeys; | ||
import org.eclipse.yasson.internal.properties.Messages; | ||
|
||
/** | ||
* Search for instance creator from other sources. | ||
* Mainly intended to add extensibility for different java versions and new features. | ||
*/ | ||
public class ClassMultiReleaseExtension { | ||
|
||
private ClassMultiReleaseExtension() { | ||
throw new IllegalStateException("This class cannot be instantiated"); | ||
} | ||
|
||
static boolean shouldTransformToPropertyName(Method method) { | ||
return !method.getDeclaringClass().isRecord(); | ||
} | ||
|
||
static boolean isSpecialAccessorMethod(Method method, Map<String, Property> classProperties) { | ||
return isRecord(method.getDeclaringClass()) | ||
&& method.getParameterCount() == 0 | ||
&& !void.class.equals(method.getReturnType()) | ||
&& classProperties.containsKey(method.getName()); | ||
} | ||
|
||
static JsonbCreator findCreator(Class<?> clazz, | ||
Constructor<?>[] declaredConstructors, | ||
AnnotationIntrospector introspector, | ||
PropertyNamingStrategy propertyNamingStrategy) { | ||
if (clazz.isRecord()) { | ||
if (declaredConstructors.length == 1) { | ||
return introspector.createJsonbCreator(declaredConstructors[0], null, clazz, propertyNamingStrategy); | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
public static boolean isRecord(Class<?> clazz) { | ||
return clazz.isRecord(); | ||
} | ||
|
||
public static Optional<JsonbException> exceptionToThrow(Class<?> clazz) { | ||
if (clazz.isRecord()) { | ||
if (clazz.getDeclaredConstructors().length > 1) { | ||
return Optional.of(new JsonbException(Messages.getMessage(MessageKeys.RECORD_MULTIPLE_CONSTRUCTORS, clazz))); | ||
} | ||
} | ||
return Optional.empty(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters