-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ensure compatibility with old style parameter objects in SET/ACT
The legacy sensiNact northbound REST provider expected parameters to be encapsulated in a JSON object, not a raw array. This should continue to work. Signed-off-by: Tim Ward <timothyjward@apache.org>
- Loading branch information
1 parent
f529ebd
commit d3a4f31
Showing
9 changed files
with
156 additions
and
17 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
25 changes: 25 additions & 0 deletions
25
...rg/eclipse/sensinact/northbound/query/dto/query/WrappedAccessMethodCallParametersDTO.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,25 @@ | ||
/********************************************************************* | ||
* Copyright (c) 2023 Contributors to the Eclipse Foundation. | ||
* | ||
* 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: | ||
* Kentyou - initial implementation | ||
**********************************************************************/ | ||
package org.eclipse.sensinact.northbound.query.dto.query; | ||
|
||
import java.util.List; | ||
|
||
import org.eclipse.sensinact.northbound.query.dto.query.jackson.WrappedAccessMethodCallParametersDeserializer; | ||
|
||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize; | ||
|
||
@JsonDeserialize(using = WrappedAccessMethodCallParametersDeserializer.class) | ||
public class WrappedAccessMethodCallParametersDTO { | ||
|
||
public List<AccessMethodCallParameterDTO> parameters; | ||
} |
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
68 changes: 68 additions & 0 deletions
68
...act/northbound/query/dto/query/jackson/WrappedAccessMethodCallParametersDeserializer.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,68 @@ | ||
/********************************************************************* | ||
* Copyright (c) 2023 Contributors to the Eclipse Foundation. | ||
* | ||
* 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: | ||
* Kentyou - initial implementation | ||
**********************************************************************/ | ||
package org.eclipse.sensinact.northbound.query.dto.query.jackson; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
|
||
import org.eclipse.sensinact.northbound.query.dto.query.AccessMethodCallParameterDTO; | ||
import org.eclipse.sensinact.northbound.query.dto.query.WrappedAccessMethodCallParametersDTO; | ||
|
||
import com.fasterxml.jackson.core.JacksonException; | ||
import com.fasterxml.jackson.core.JsonParser; | ||
import com.fasterxml.jackson.core.JsonToken; | ||
import com.fasterxml.jackson.core.type.TypeReference; | ||
import com.fasterxml.jackson.databind.DeserializationContext; | ||
import com.fasterxml.jackson.databind.JsonMappingException; | ||
import com.fasterxml.jackson.databind.deser.std.StdDeserializer; | ||
|
||
/** | ||
* Handles the deserialization of method parameters | ||
*/ | ||
public class WrappedAccessMethodCallParametersDeserializer | ||
extends StdDeserializer<WrappedAccessMethodCallParametersDTO> { | ||
|
||
private static final long serialVersionUID = 1L; | ||
|
||
public WrappedAccessMethodCallParametersDeserializer() { | ||
this(null); | ||
} | ||
|
||
protected WrappedAccessMethodCallParametersDeserializer(final Class<?> vc) { | ||
super(vc); | ||
} | ||
|
||
@Override | ||
public WrappedAccessMethodCallParametersDTO deserialize(final JsonParser parser, final DeserializationContext ctxt) | ||
throws IOException, JacksonException { | ||
|
||
WrappedAccessMethodCallParametersDTO dto = new WrappedAccessMethodCallParametersDTO(); | ||
if (parser.currentToken() == JsonToken.START_OBJECT) { | ||
if ("parameters".equals(parser.nextFieldName())) { | ||
// Look for the array | ||
parser.nextToken(); | ||
} else { | ||
throw new JsonMappingException(parser, "Expected the field name to be \"parameters\"", | ||
parser.currentTokenLocation()); | ||
} | ||
} | ||
if (parser.currentToken() == JsonToken.START_ARRAY) { | ||
dto.parameters = parser.readValueAs(new TypeReference<List<AccessMethodCallParameterDTO>>() { | ||
}); | ||
} else { | ||
throw new JsonMappingException(parser, "Invalid token " + parser.currentToken() + " expected ARRAY_START", | ||
parser.currentTokenLocation()); | ||
} | ||
return dto; | ||
} | ||
} |
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
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