forked from eclipse/kapua
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: changed the way CustomMoxyJsonProvider is set in order to solve …
…"Error deserializing object from entity stream" error message upon auth
- Loading branch information
angelo.andreussi
committed
Oct 21, 2024
1 parent
2cba245
commit be39606
Showing
3 changed files
with
54 additions
and
35 deletions.
There are no files selected for viewing
34 changes: 0 additions & 34 deletions
34
rest-api/web/src/main/java/org/eclipse/kapua/app/api/web/CustomMoxyJsonProvider.java
This file was deleted.
Oops, something went wrong.
53 changes: 53 additions & 0 deletions
53
...pi/web/src/main/java/org/eclipse/kapua/app/api/web/MoxyJsonFeatureCustomJsonProvider.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,53 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2016, 2022 Eurotech and/or its affiliates and others | ||
* | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Eurotech - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.kapua.app.api.web; | ||
|
||
import org.glassfish.jersey.internal.InternalProperties; | ||
import org.glassfish.jersey.internal.util.PropertiesHelper; | ||
import javax.ws.rs.core.Configuration; | ||
import javax.ws.rs.core.Feature; | ||
import javax.ws.rs.core.FeatureContext; | ||
import javax.ws.rs.core.MediaType; | ||
import javax.ws.rs.core.MultivaluedMap; | ||
import javax.ws.rs.ext.Provider; | ||
import javax.xml.bind.JAXBException; | ||
import javax.xml.bind.Unmarshaller; | ||
import javax.xml.bind.helpers.DefaultValidationEventHandler; | ||
import java.lang.annotation.Annotation; | ||
import java.lang.reflect.Type; | ||
|
||
public class MoxyJsonFeatureCustomJsonProvider implements Feature { | ||
//A custom feature used to set a custom moxyJsonProvider | ||
|
||
private static final String JSON_FEATURE = MoxyJsonFeatureCustomJsonProvider.class.getSimpleName(); | ||
|
||
@Override | ||
public boolean configure(final FeatureContext context) { | ||
final Configuration config = context.getConfiguration(); | ||
// Disable other JSON providers. In this way the org.glassfish.jersey.moxy.json.MoxyJsonFeature (registered as default by MOXy) will skip the registration of the default provider | ||
context.property(PropertiesHelper.getPropertyNameForRuntime(InternalProperties.JSON_FEATURE, config.getRuntimeType()), | ||
JSON_FEATURE); | ||
context.register(CustomMoxyJsonProvider.class); | ||
return true; | ||
} | ||
|
||
@Provider | ||
public static class CustomMoxyJsonProvider extends org.glassfish.jersey.moxy.json.internal.ConfigurableMoxyJsonProvider { | ||
//A custom moxyJsonProvider that sets the unmarshaller validationEventHandler to the default one. This one allows to propagate exceptions to the stack when an error is found (for example, when an exception has been thrown from one of our custom "xmlAdapters") | ||
@Override | ||
protected void preReadFrom(Class<Object> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, Unmarshaller unmarshaller) throws JAXBException { | ||
super.preReadFrom(type, genericType, annotations, mediaType, httpHeaders, unmarshaller); | ||
unmarshaller.setEventHandler(new DefaultValidationEventHandler()); | ||
} | ||
} | ||
} |
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