Skip to content

Commit

Permalink
feat(xjx-serdes): add simple argument type support for List and Set
Browse files Browse the repository at this point in the history
  • Loading branch information
jonas-grgt committed Jan 16, 2024
1 parent 01ca574 commit 9962112
Show file tree
Hide file tree
Showing 24 changed files with 1,081 additions and 346 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ jobs:
distribution: 'temurin'
cache: maven
- name: Build with Maven
run: mvn -B package --file pom.xml
run: mvn -B verify --file pom.xml
91 changes: 44 additions & 47 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,59 +1,56 @@
name: release
name: Release

on:
workflow_dispatch:
inputs:
tag:
type: string
description: tag

env:
INPUT_VERSION: '0.2.0'

jobs:
release:
name: Release
bump_version:
name: "Bump Version"
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v3
- uses: actions/checkout@v3
- name: Set up Java
uses: actions/setup-java@v3
with:
fetch-depth: 0

# Configure build steps as you'd normally do

- name: Setup Java
java-version: '17'
distribution: 'adopt'
- name: Bump version
id: bump
run: "./mvnw versions:set -DnewVersion=${{ github.event.inputs.tag }} -DprocessAllModules && ./mvnw versions:commit -DprocessAllModules"
- name: Commit bumped version
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: "Bump version to ${{ github.event.inputs.tag }}"
publish:
needs: [bump_version]
runs-on: ubuntu-latest
steps:
- name: wait for version bump
run: sleep 5
- uses: actions/checkout@v3
- name: Set up Java
uses: actions/setup-java@v3
with:
java-version: 21
distribution: 'zulu'
server-id: central
server-username: MAVEN_USERNAME
server-password: MAVEN_CENTRAL_TOKEN
gpg-private-key: ${{ secrets.GPG_PRIVATE_KEY }}
gpg-passphrase: MAVEN_GPG_PASSPHRASE

# Post JARs to Maven Central

- name: Release to Maven Central
env:
MAVEN_USERNAME: ${{ secrets.SONATYPE_USERNAME }}
MAVEN_CENTRAL_TOKEN: ${{ secrets.SONATYPE_PASSWORD }}
MAVEN_GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
run: |
export GPG_TTY=$(tty)
git config user.name "JonasG"
git config user.email "jonas.grgt@gmail.com"
mvn -B --file pom.xml release:prepare release:perform
# Create a release

- name: Run JReleaser
uses: jreleaser/release-action@v2
java-version: '17'
distribution: 'adopt'
- name: Tag Release
uses: tvdias/github-tagger@v0.0.1
with:
repo-token: "${{ secrets.GITHUB_TOKEN }}"
tag: "v${{ github.event.inputs.tag }}"
- name: Release
env:
JRELEASER_NEXUS2_USERNAME: ${{ secrets.JRELEASER_NEXUS2_USERNAME }}
JRELEASER_NEXUS2_PASSWORD: ${{ secrets.JRELEASER_NEXUS2_PASSWORD }}
JRELEASER_GPG_PASSPHRASE: ${{ secrets.JRELEASER_GPG_PASSPHRASE }}
JRELEASER_GPG_SECRET_KEY: ${{ secrets.JRELEASER_GPG_SECRET_KEY }}
JRELEASER_GPG_PUBLIC_KEY: ${{ secrets.JRELEASER_GPG_PUBLIC_KEY }}
JRELEASER_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

# Persist logs

- name: JReleaser release output
if: always()
uses: actions/upload-artifact@v3
with:
name: jreleaser-release
path: |
out/jreleaser/trace.log
out/jreleaser/output.properties
run: ./mvnw -Prelease deploy jreleaser:full-release -DaltDeploymentRepository=local::file:./target/staging-deploy --non-recursive
Binary file added .mvn/wrapper/maven-wrapper.jar
Binary file not shown.
18 changes: 18 additions & 0 deletions .mvn/wrapper/maven-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.4/apache-maven-3.9.4-bin.zip
wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.1/maven-wrapper-3.1.1.jar
87 changes: 36 additions & 51 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ public class Location {
private Location() {
}

@Tag(path = "/WeatherData/Location/City")
@Tag(path = "City")
private String City;

@Tag(path = "/WeatherData/Location/Country")
@Tag(path = "Country")
private String Country;
}
```
Expand All @@ -68,7 +68,7 @@ String document = """
<CurrentConditions>
<Temperature>
<Value>75</Value>
<Unit>°F</Unit>
<Unit><![CDATA[°F]]></Unit>
</Temperature>
<Humidity>
<Value>60</Value>
Expand Down Expand Up @@ -134,71 +134,56 @@ class Temperature {


### Collection types
When deserializing XML data containing a collection type, the following conventions apply:
When deserializing an XML document containing repeated elements, it can be mapped onto one of the collection types `List` or `Set`.

The following conventions should be followed:

- Only `List` and `Set` types are supported
- The List or Set field should be annotated with `@Tag` having a `path` pointing to the containing tag that holds the repeated tags.
- The nested complex type should be annotated top-level with `@Tag` having a `path` pointing to a single element that is repeated
- Fields within the nested complex type can be annotated as usual.
- Only `List` and `Set` types are supported for mapping repeated elements.
- The `@Tag` annotation should be used on a `List` or `Set` field.
- Include a `path` attribute pointing to the containing tag that holds the repeated tags.
- Include an `items` attribute pointing to the repeated tag, relatively.
- The `path` attribute supports both relative and absolute paths.
- The generic argument can be any standard simple type (e.g., `String`, `Boolean`, `Double`, `Long`, etc.) or a custom complex type.
- Fields within the nested complex type can be annotated as usual, using relative or absolute paths.

Example XML document:

```xml
<?xml version="1.0" encoding="UTF-8"?>
<WeatherData>
<Forecasts>
<Day Date="2023-09-12">
<High>
<Value>71</Value>
</High>
<Low>
<Value>62</Value>
</Low>
</Day>
<Forecasts>
<Day Date="2023-09-12">
<High>
<Value>71</Value>
</High>
<Low>
<Value>62</Value>
</Low>
</Day>
<Day Date="2023-09-13">
<High>
<Value>78</Value>
</High>
<Low>
<Value>71</Value>
</Low>
<High>
<Value>78</Value>
</High>
<Low>
<Value>71</Value>
</Low>
</Day>
</Forecasts>
</WeatherData>
```

```java
public class WeatherData {
// When mapping List or Set the type needs to point to the
// tag containing the repeated elements
@Tag(path = "/WeatherData/Forecasts")
List<Forecast> forecasts;
}

// Top level annoation is required and
// needs to point to an indiviual element that is repeated
@Tag(path = "/WeatherData/Forecasts/Day")
public class Forecast {
// field can be both absolutely as relatively mapped
@Tag(path = "High/Value")
String maxTemperature;

// field can be both absolutely as relatively mapped
@Tag(path = "/WeatherData/Forecasts/Day/Low/Value")
String minTemperature;
}
```

### Map types

Maps can be deserialized either as a field or a top-level type. Consider the following XML document:
```xml
<?xml version="1.0" encoding="UTF-8"?>
<WeatherData>
<CurrentConditions>
<Temperature>
<Value>75</Value>
<Unit>°F</Unit>
</Temperature>
</CurrentConditions>
<CurrentConditions>
<Temperature>
<Value>75</Value>
<Unit>°F</Unit>
</Temperature>
</CurrentConditions>
</WeatherData>
```

Expand Down
Loading

0 comments on commit 9962112

Please sign in to comment.