Package se.digg.dgc.payload.v1
Class DigitalCovidCertificate
- java.lang.Object
-
- se.digg.dgc.payload.v1.Eudcc
-
- se.digg.dgc.payload.v1.DigitalCovidCertificate
-
public class DigitalCovidCertificate extends Eudcc
A wrapper for the root element generated from the Schema. This class offers methods for encoding and decoding to/from CBOR and JSON.The class also ensures that subject names are properly transliterated.
If you are using the builder pattern (withXX-methods) you need to cast the result to a
DigitalCovidCertificate
instance.final DigitalCovidCertificate dcc = (DigitalCovidCertificate) new DigitalCovidCertificate() .withNam(new PersonName().withGn("...").withFn("...")) .withDob(LocalDate.parse("1969-11-11")) .withV(Arrays.asList(new VaccinationEntry() .withTg("840539006") .withVp("1119349007") ... .withCi("01:SE:JKJKHJGHG6768686HGJGH#M")));
- Author:
- Martin Lindström (martin@idsec.se), Henrik Bengtsson (extern.henrik.bengtsson@digg.se), Henric Norlander (extern.henric.norlander@digg.se)
-
-
Constructor Summary
Constructors Constructor Description DigitalCovidCertificate()
Default constructor.DigitalCovidCertificate(PersonName name, LocalDate dateOfBirth)
Constructor assigning the subject name and date of birth of the subject.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static DigitalCovidCertificate
decode(byte[] cbor)
Decodes a CBOR encoding to aDigitalCovidCertificate
.byte[]
encode()
Encodes this object to its CBOR byte representation.static DigitalCovidCertificate
fromJsonString(String json)
Decodes a JSON string into aDigitalCovidCertificate
.static com.fasterxml.jackson.dataformat.cbor.databind.CBORMapper
getCBORMapper()
Gets a configuredCBORMapper
to use for serializing and deserializing.DateOfBirth
getDateOfBirth()
Gets thedob
field as aDateOfBirth
object.static com.fasterxml.jackson.databind.ObjectMapper
getJSONMapper()
Gets a configuredObjectMapper
to use for JSON serializing and deserializing.void
setDob(LocalDate dob)
Setter that takes aLocalDate
representing the date of birth instead of string.void
setDob(DateOfBirth dob)
Setter that takes aDateOfBirth
representing the date of birth instead of string.void
setNam(PersonName name)
Makes sure that the names supplied are transliterated.void
setTagDateTimes(boolean tagDateTimes)
The specification dictates that we should tag date-time strings with 0, but during interoperability testing some validator apps have had problems with this.String
toJSONString()
Gets this object as a JSON string.String
toString()
Eudcc
withDob(LocalDate dob)
An alternative toEudcc.withDob(String)
where the date of birth is represented as aLocalDate
.Eudcc
withDob(DateOfBirth dob)
An alternative toEudcc.withDob(String)
where the date of birth is represented as aDateOfBirth
.Eudcc
withNam(PersonName name)
Makes sure that the names supplied are transliterated.
-
-
-
Constructor Detail
-
DigitalCovidCertificate
public DigitalCovidCertificate()
Default constructor.
-
DigitalCovidCertificate
public DigitalCovidCertificate(PersonName name, LocalDate dateOfBirth)
Constructor assigning the subject name and date of birth of the subject.- Parameters:
name
- the subject namedateOfBirth
- the date of birth of the subject
-
-
Method Detail
-
setNam
public void setNam(PersonName name)
Makes sure that the names supplied are transliterated.
-
withNam
public Eudcc withNam(PersonName name)
Makes sure that the names supplied are transliterated.
-
getDateOfBirth
public DateOfBirth getDateOfBirth() throws DateTimeException
Gets thedob
field as aDateOfBirth
object.- Returns:
- a DateOfBirth object or null if the dob field is not present
- Throws:
DateTimeException
- for date parsing errors
-
setDob
public void setDob(LocalDate dob)
Setter that takes aLocalDate
representing the date of birth instead of string.- Parameters:
dob
- the date of birth
-
setDob
public void setDob(DateOfBirth dob)
Setter that takes aDateOfBirth
representing the date of birth instead of string.- Parameters:
dob
- the date of birth
-
withDob
public Eudcc withDob(LocalDate dob)
An alternative toEudcc.withDob(String)
where the date of birth is represented as aLocalDate
.- Parameters:
dob
- the date of birth- Returns:
- this object
-
withDob
public Eudcc withDob(DateOfBirth dob)
An alternative toEudcc.withDob(String)
where the date of birth is represented as aDateOfBirth
.- Parameters:
dob
- the date of birth- Returns:
- this object
-
encode
public byte[] encode() throws DGCSchemaException
Encodes this object to its CBOR byte representation.- Returns:
- the CBOR encoding
- Throws:
DGCSchemaException
- for encoding errors
-
decode
public static DigitalCovidCertificate decode(byte[] cbor) throws DGCSchemaException
Decodes a CBOR encoding to aDigitalCovidCertificate
.- Parameters:
cbor
- the CBOR encoding- Returns:
- a DigitalCovidCertificate
- Throws:
DGCSchemaException
- for decoding errors
-
toJSONString
public String toJSONString() throws DGCSchemaException
Gets this object as a JSON string.Mainly for debugging.
- Returns:
- JSON string
- Throws:
DGCSchemaException
- fort encoding errors
-
fromJsonString
public static DigitalCovidCertificate fromJsonString(String json) throws DGCSchemaException
Decodes a JSON string into aDigitalCovidCertificate
.- Parameters:
json
- the JSON representation- Returns:
- a DigitalCovidCertificate
- Throws:
DGCSchemaException
- for decoding errors
-
getCBORMapper
public static com.fasterxml.jackson.dataformat.cbor.databind.CBORMapper getCBORMapper()
Gets a configuredCBORMapper
to use for serializing and deserializing.- Returns:
- a CBORMapper
-
getJSONMapper
public static com.fasterxml.jackson.databind.ObjectMapper getJSONMapper()
Gets a configuredObjectMapper
to use for JSON serializing and deserializing.- Returns:
- an ObjectMapper
-
setTagDateTimes
public void setTagDateTimes(boolean tagDateTimes)
The specification dictates that we should tag date-time strings with 0, but during interoperability testing some validator apps have had problems with this. Therefore, it is possible to turn off tagging.The default is to add the CBOR tag 0 for date-times.
- Parameters:
tagDateTimes
- whether to tag date-times.
-
-