-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge release release-1.1.0 branch into main (#96)
* docs: README tuning * refactor: Reduce E164PhoneNumber verbosity related to invalid E164 format * refactor: auto-subscribe tutorial moved to sinch-sdk-java-quickstart repository * Verification 2.0.1 for 1.1 release * [release] Set release & tag: 1.1.0 * [release] Set next version: 1.1.1-SNAPSHOT --------- Co-authored-by: Jean-Pierre Portier <[email protected]> Co-authored-by: Jean-Pierre Portier <[email protected]> Co-authored-by: git <[email protected]>
- Loading branch information
1 parent
c01bc1f
commit 3a32964
Showing
337 changed files
with
22,136 additions
and
18,305 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
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
79 changes: 79 additions & 0 deletions
79
client/src/main/com/sinch/sdk/domains/verification/adapters/IdentityMapper.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,79 @@ | ||
package com.sinch.sdk.domains.verification.adapters; | ||
|
||
import com.fasterxml.jackson.core.JsonGenerator; | ||
import com.fasterxml.jackson.core.JsonParser; | ||
import com.fasterxml.jackson.databind.DeserializationContext; | ||
import com.fasterxml.jackson.databind.SerializerProvider; | ||
import com.fasterxml.jackson.databind.deser.std.StdDeserializer; | ||
import com.fasterxml.jackson.databind.module.SimpleModule; | ||
import com.fasterxml.jackson.databind.ser.std.StdSerializer; | ||
import com.sinch.sdk.core.utils.databind.Mapper; | ||
import com.sinch.sdk.domains.verification.models.v1.Identity; | ||
import com.sinch.sdk.domains.verification.models.v1.NumberIdentity; | ||
import com.sinch.sdk.domains.verification.models.v1.internal.IdentityInternal; | ||
import com.sinch.sdk.domains.verification.models.v1.internal.IdentityInternal.TypeEnum; | ||
import java.io.IOException; | ||
import java.util.logging.Logger; | ||
|
||
public class IdentityMapper { | ||
private static final Logger LOGGER = Logger.getLogger(IdentityMapper.class.getName()); | ||
|
||
public static void initMapper() { | ||
SimpleModule module = | ||
new SimpleModule() | ||
.addSerializer(Identity.class, new Serializer()) | ||
.addDeserializer(Identity.class, new IdentityDeserializer()); | ||
Mapper.getInstance().registerModule(module); | ||
} | ||
|
||
static class Serializer extends StdSerializer<Identity> { | ||
|
||
public Serializer() { | ||
this(null); | ||
} | ||
|
||
public Serializer(Class<Identity> t) { | ||
super(t); | ||
} | ||
|
||
@Override | ||
public void serialize(Identity raw, JsonGenerator jgen, SerializerProvider provider) | ||
throws IOException { | ||
if (!(raw instanceof NumberIdentity)) { | ||
// avoid exception | ||
LOGGER.severe("Unexpected type'" + raw + "'"); | ||
return; | ||
} | ||
NumberIdentity identity = (NumberIdentity) raw; | ||
IdentityInternal.Builder internal = | ||
IdentityInternal.builder().setType(TypeEnum.NUMBER).setEndpoint(identity.getEndpoint()); | ||
|
||
jgen.writeObject(internal.build()); | ||
} | ||
} | ||
|
||
static final class IdentityDeserializer extends StdDeserializer<Identity> { | ||
|
||
private static final long serialVersionUID = 1L; | ||
|
||
public IdentityDeserializer() { | ||
this(Identity.class); | ||
} | ||
|
||
public IdentityDeserializer(Class<?> vc) { | ||
super(vc); | ||
} | ||
|
||
@Override | ||
public Identity deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException { | ||
|
||
IdentityInternal internal = Mapper.getInstance().readValue(jp, IdentityInternal.class); | ||
if (!internal.getType().equals(TypeEnum.NUMBER)) { | ||
// avoid exception | ||
LOGGER.severe("Unexpected type'" + internal + "'"); | ||
return NumberIdentity.valueOf(""); | ||
} | ||
return NumberIdentity.valueOf(internal.getEndpoint()); | ||
} | ||
} | ||
} |
Oops, something went wrong.