Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#726 make jsonb adapters null safe #727

Merged
merged 3 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
*/
package hu.icellmobilsoft.coffee.tool.jsonb.adapter;

import java.time.YearMonth;

import jakarta.json.bind.JsonbException;
import jakarta.json.bind.adapter.JsonbAdapter;

Expand All @@ -45,9 +43,18 @@ public String adaptToJson(Class<?> obj) {
return obj.getName();
}

/** {@inheritDoc} */
/**
* Converts a {@link String} into a {@link Class}
*
* @param obj
* string to convert or {@code null}.
* @return the converted object or {@code null}, if the given {@code date} param is null
*/
@Override
public Class<?> adaptFromJson(String obj) {
if (obj == null) {
korneldanko marked this conversation as resolved.
Show resolved Hide resolved
return null;
}
try {
return Class.forName(obj);
} catch (ClassNotFoundException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,18 @@ public Long adaptToJson(Date date) {
return date.getTime();
}

/** {@inheritDoc} */
/**
* Converts a {@link Long} into a {@link Date} object
*
* @param date
* Long to convert or {@code null}.
* @return the converted object or {@code null}, if the given {@code date} param is null
*/
@Override
public Date adaptFromJson(Long date) {
if (date == null) {
return null;
}
try {
return new Date(date);
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,18 @@ public String adaptToJson(Duration duration) {
return String.valueOf(duration);
}

/** {@inheritDoc} */
/**
* Converts a {@link String} into a {@link Duration} object
*
* @param duration
* string to convert or {@code null}.
* @return the converted object or {@code null}, if the given {@code duration} param is null
*/
@Override
public Duration adaptFromJson(String duration) {
if (duration == null) {
return null;
}
return DateXmlUtil.getDatatypeFactory().newDuration(duration);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,18 @@ public String adaptToJson(XMLGregorianCalendar calendar) {
return calendar.toXMLFormat();
}

/** {@inheritDoc} */
/**
* Converts a {@link String}r into a {@link XMLGregorianCalendar} object
*
* @param calendar
* string to convert or {@code null}.
* @return the converted object or {@code null}, if the given {@code calendar} param is null
*/
@Override
public XMLGregorianCalendar adaptFromJson(String calendar) {
if (calendar == null) {
return null;
}
try {
XMLGregorianCalendar xmlCal = toXMLGregorianCalendar(calendar);
return xmlCal.normalize();
Expand Down
8 changes: 7 additions & 1 deletion docs/en/migration/migration290to2100.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,10 @@ Changes are backwards compatible doesnt need any migration.
Java11 support has been removed from the ci build process, and the default Java version has been changed to 17.

==== Migration
The minimum supported Java version is 17.
The minimum supported Java version is 17.

=== coffee-tool
The default custom jsonb adapters have become null safe.

==== Migration
Changes are backwards compatible doesnt need any migration.
8 changes: 7 additions & 1 deletion docs/hu/migration/migration290to2100.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,10 @@ A változtatások nem eredményeznek átállási munkálatokat, visszafelé komp
A ci build folyamatból el lett távolítva a java11 támogatás, és az alapértelmezett java verzió a 17 lett.

==== Migration
A legkisebb támogatott java verzió a 17-es.
A legkisebb támogatott java verzió a 17-es.

=== coffee-tool
Az alapértelmezett egyedi jsob adapterek null safe-ek lettek.

==== Migration
A változtatások nem eredményeznek átállási munkálatokat, visszafelé kompatibilis.
Loading