Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
X
xta-client-lib
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
OZG-Cloud
lib
xta-client-lib
Commits
5cd3b5fb
Commit
5cd3b5fb
authored
1 month ago
by
Lukas Malte Monnerjahn
Browse files
Options
Downloads
Patches
Plain Diff
no implicit type cast when loading yaml
parent
23d18ec8
No related branches found
No related tags found
No related merge requests found
Pipeline
#2288
failed
1 month ago
Stage: build
Stage: test
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/test/java/de/ozgcloud/xta/client/extension/XtaMessageExampleLoader.java
+17
-2
17 additions, 2 deletions
...zgcloud/xta/client/extension/XtaMessageExampleLoader.java
with
17 additions
and
2 deletions
src/test/java/de/ozgcloud/xta/client/extension/XtaMessageExampleLoader.java
+
17
−
2
View file @
5cd3b5fb
...
@@ -23,7 +23,13 @@ import jakarta.validation.constraints.NotBlank;
...
@@ -23,7 +23,13 @@ import jakarta.validation.constraints.NotBlank;
import
org.apache.commons.codec.Resources
;
import
org.apache.commons.codec.Resources
;
import
org.apache.commons.io.IOUtils
;
import
org.apache.commons.io.IOUtils
;
import
org.yaml.snakeyaml.DumperOptions
;
import
org.yaml.snakeyaml.LoaderOptions
;
import
org.yaml.snakeyaml.Yaml
;
import
org.yaml.snakeyaml.Yaml
;
import
org.yaml.snakeyaml.constructor.Constructor
;
import
org.yaml.snakeyaml.nodes.Tag
;
import
org.yaml.snakeyaml.representer.Representer
;
import
org.yaml.snakeyaml.resolver.Resolver
;
import
de.ozgcloud.xta.client.model.XtaFile
;
import
de.ozgcloud.xta.client.model.XtaFile
;
import
de.ozgcloud.xta.client.model.XtaIdentifier
;
import
de.ozgcloud.xta.client.model.XtaIdentifier
;
...
@@ -33,7 +39,8 @@ import lombok.Builder;
...
@@ -33,7 +39,8 @@ import lombok.Builder;
public
class
XtaMessageExampleLoader
{
public
class
XtaMessageExampleLoader
{
static
Yaml
yaml
=
new
Yaml
();
static
Yaml
yaml
=
new
Yaml
(
new
Constructor
(
new
LoaderOptions
()),
new
Representer
(
new
DumperOptions
()),
new
DumperOptions
(),
new
StringYamlResolver
());
@SuppressWarnings
(
"unchecked"
)
@SuppressWarnings
(
"unchecked"
)
public
static
XtaMessage
load
(
MessageExampleConfig
config
)
{
public
static
XtaMessage
load
(
MessageExampleConfig
config
)
{
...
@@ -137,7 +144,7 @@ public class XtaMessageExampleLoader {
...
@@ -137,7 +144,7 @@ public class XtaMessageExampleLoader {
return
Optional
.
ofNullable
(
map
.
get
(
key
))
return
Optional
.
ofNullable
(
map
.
get
(
key
))
.
filter
(
String
.
class
::
isInstance
)
.
filter
(
String
.
class
::
isInstance
)
.
map
(
String
.
class
::
cast
)
.
map
(
String
.
class
::
cast
)
.
orElse
Throw
(()
->
new
IllegalArgumentException
(
"Missing key: %s"
.
formatted
(
key
))
);
.
orElse
(
null
);
}
}
private
static
XtaMessageMetaData
mapXtaMessageMetadata
(
Map
<
String
,
Object
>
metaData
,
MessageExampleConfig
config
)
{
private
static
XtaMessageMetaData
mapXtaMessageMetadata
(
Map
<
String
,
Object
>
metaData
,
MessageExampleConfig
config
)
{
...
@@ -221,4 +228,12 @@ public class XtaMessageExampleLoader {
...
@@ -221,4 +228,12 @@ public class XtaMessageExampleLoader {
));
));
}
}
/** Custom YAML resolver to treat every scalar as string, instead of using implicit type casting */
public
static
class
StringYamlResolver
extends
Resolver
{
@Override
protected
void
addImplicitResolvers
()
{
addImplicitResolver
(
Tag
.
NULL
,
EMPTY
,
null
);
}
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment