generated from micronaut-projects/micronaut-project-template
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support renaming constructor arguments and choosing a different const…
…ructor by mixins (#804)
- Loading branch information
Showing
12 changed files
with
621 additions
and
28 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
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
47 changes: 47 additions & 0 deletions
47
serde-jackson/src/test/groovy/io/micronaut/serde/jackson/serdeimport/JodaDateTimeSerde.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,47 @@ | ||
/* | ||
* Copyright 2017-2021 original authors | ||
* | ||
* Licensed 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. | ||
*/ | ||
package io.micronaut.serde.jackson.serdeimport; | ||
|
||
import com.amazonaws.services.lambda.runtime.serialization.util.SerializeUtil; | ||
import io.micronaut.context.annotation.Requires; | ||
import io.micronaut.core.annotation.NonNull; | ||
import io.micronaut.core.type.Argument; | ||
import io.micronaut.serde.Decoder; | ||
import io.micronaut.serde.Encoder; | ||
import io.micronaut.serde.util.NullableSerde; | ||
import jakarta.inject.Singleton; | ||
import org.joda.time.DateTime; | ||
|
||
import java.io.IOException; | ||
|
||
@Singleton | ||
@Requires(classes = DateTime.class) | ||
public class JodaDateTimeSerde implements NullableSerde<DateTime> { | ||
|
||
@Override | ||
public void serialize(@NonNull Encoder encoder, | ||
@NonNull EncoderContext context, | ||
@NonNull Argument<? extends DateTime> type, | ||
@NonNull DateTime value) throws IOException { | ||
encoder.encodeString(SerializeUtil.serializeDateTime(value, getClass().getClassLoader())); | ||
} | ||
|
||
@Override | ||
@NonNull | ||
public DateTime deserializeNonNull(Decoder decoder, DecoderContext decoderContext, Argument<? super DateTime> type) throws IOException { | ||
return SerializeUtil.deserializeDateTime(DateTime.class, decoder.decodeString()); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
...n/src/test/groovy/io/micronaut/serde/jackson/serdeimport/ResponseElementsEntitySerde.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,40 @@ | ||
/* | ||
* Copyright 2017-2023 original authors | ||
* | ||
* Licensed 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. | ||
*/ | ||
package io.micronaut.serde.jackson.serdeimport; | ||
|
||
import com.amazonaws.lambda.thirdparty.com.fasterxml.jackson.annotation.JsonCreator; | ||
import com.amazonaws.lambda.thirdparty.com.fasterxml.jackson.annotation.JsonGetter; | ||
import com.amazonaws.lambda.thirdparty.com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.amazonaws.services.lambda.runtime.events.models.s3.S3EventNotification; | ||
import io.micronaut.serde.annotation.SerdeImport; | ||
|
||
@SerdeImport(value = S3EventNotification.ResponseElementsEntity.class, mixin = ResponseElementsEntitySerde.ResponseElementsEntityMixin.class) | ||
public class ResponseElementsEntitySerde { | ||
private static final String X_AMZ_ID_2 = "x-amz-id-2"; | ||
private static final String X_AMZ_REQUEST_ID = "x-amz-request-id"; | ||
|
||
static abstract class ResponseElementsEntityMixin { | ||
@JsonGetter(X_AMZ_ID_2) | ||
abstract String getxAmzId2(); | ||
|
||
@JsonGetter(X_AMZ_REQUEST_ID) | ||
abstract String getxAmzRequestId(); | ||
|
||
@JsonCreator | ||
ResponseElementsEntityMixin(@JsonProperty(X_AMZ_ID_2) String xAmzId2, @JsonProperty(X_AMZ_REQUEST_ID) String xAmzRequestId) { | ||
} | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
...kson/src/test/groovy/io/micronaut/serde/jackson/serdeimport/S3EventNotificationSerde.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,41 @@ | ||
/* | ||
* Copyright 2017-2023 original authors | ||
* | ||
* Licensed 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. | ||
*/ | ||
package io.micronaut.serde.jackson.serdeimport; | ||
|
||
import com.amazonaws.lambda.thirdparty.com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.amazonaws.services.lambda.runtime.events.models.s3.S3EventNotification; | ||
import io.micronaut.serde.annotation.SerdeImport; | ||
|
||
import java.util.List; | ||
|
||
@SerdeImport(value = S3EventNotification.class, mixin = S3EventNotificationSerde.S3EventNotificationMixin.class) | ||
@SerdeImport(value = S3EventNotification.S3Entity.class) | ||
@SerdeImport(value = S3EventNotification.RequestParametersEntity.class) | ||
@SerdeImport(value = S3EventNotification.S3BucketEntity.class) | ||
@SerdeImport(value = S3EventNotification.UserIdentityEntity.class) | ||
@SerdeImport(value = S3EventNotification.S3EventNotificationRecord.class) | ||
public class S3EventNotificationSerde { | ||
/** | ||
* Records Mixin. | ||
*/ | ||
public interface S3EventNotificationMixin { | ||
/** | ||
* @return Records. | ||
*/ | ||
@JsonProperty("Records") | ||
List<S3EventNotification.S3EventNotificationRecord> getRecords(); | ||
} | ||
} |
Oops, something went wrong.