forked from devonfw/IDEasy
-
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.
devonfw#634: added DependencyInfoDeserializer (devonfw#641)
- Loading branch information
Showing
3 changed files
with
75 additions
and
6 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
cli/src/main/java/com/devonfw/tools/ide/json/DependencyInfoDeserializer.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,49 @@ | ||
package com.devonfw.tools.ide.json; | ||
|
||
import java.io.IOException; | ||
|
||
import com.devonfw.tools.ide.url.model.file.json.DependencyInfo; | ||
import com.devonfw.tools.ide.version.VersionRange; | ||
import com.fasterxml.jackson.core.JacksonException; | ||
import com.fasterxml.jackson.core.JsonParser; | ||
import com.fasterxml.jackson.core.JsonToken; | ||
import com.fasterxml.jackson.databind.DeserializationContext; | ||
import com.fasterxml.jackson.databind.JsonDeserializer; | ||
|
||
/** | ||
* {@link JsonDeserializer} for {@link DependencyInfo}. | ||
*/ | ||
public class DependencyInfoDeserializer extends JsonDeserializer<DependencyInfo> { | ||
|
||
@Override | ||
public DependencyInfo deserialize(JsonParser p, DeserializationContext context) throws IOException, JacksonException { | ||
|
||
JsonToken token = p.getCurrentToken(); | ||
if (token == JsonToken.START_OBJECT) { | ||
token = p.nextToken(); | ||
String tool = null; | ||
VersionRange versionRange = null; | ||
while (token == JsonToken.FIELD_NAME) { | ||
String property = p.currentName(); | ||
if (property.equals("tool")) { | ||
token = p.nextToken(); | ||
assert token == JsonToken.VALUE_STRING; | ||
tool = p.getValueAsString(); | ||
} else if (property.equals("versionRange")) { | ||
token = p.nextToken(); | ||
assert (token == JsonToken.START_OBJECT) || (token == JsonToken.VALUE_STRING); | ||
versionRange = p.readValueAs(VersionRange.class); | ||
} else { | ||
// ignore unknown property | ||
// currently cannot log here due to https://github.com/devonfw/IDEasy/issues/404 | ||
} | ||
token = p.nextToken(); | ||
} | ||
if ((tool != null) && (versionRange != null)) { | ||
return new DependencyInfo(tool, versionRange); | ||
} | ||
} | ||
throw new IllegalArgumentException("Invalid JSON for DependencyInfo!"); | ||
} | ||
|
||
} |
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