-
Notifications
You must be signed in to change notification settings - Fork 185
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9054 from parlt91/fix-http-api-date-format
Fix date format when using the HTTP API to use iso8601 date
- Loading branch information
Showing
4 changed files
with
56 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Copyright (c) 2024 SUSE LLC | ||
* | ||
* This software is licensed to you under the GNU General Public License, | ||
* version 2 (GPLv2). There is NO WARRANTY for this software, express or | ||
* implied, including the implied warranties of MERCHANTABILITY or FITNESS | ||
* FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2 | ||
* along with this software; if not, see | ||
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt. | ||
* | ||
* Red Hat trademarks are not licensed under GPLv2. No permission is | ||
* granted to use or replicate Red Hat trademarks that are incorporated | ||
* in this software or its documentation. | ||
*/ | ||
|
||
package com.suse.manager.api; | ||
|
||
import com.google.gson.JsonElement; | ||
import com.google.gson.JsonPrimitive; | ||
import com.google.gson.JsonSerializationContext; | ||
import com.google.gson.JsonSerializer; | ||
|
||
import java.lang.reflect.Type; | ||
import java.text.DateFormat; | ||
import java.text.SimpleDateFormat; | ||
import java.util.Date; | ||
import java.util.TimeZone; | ||
|
||
/** | ||
* Custom {@link Date} serializer to output Date objects in iso8601 format | ||
*/ | ||
public class DateSerializer implements JsonSerializer<Date> { | ||
|
||
private final DateFormat dateFormat; | ||
|
||
/** | ||
* Initialize dateFormat and set timezone to UTC | ||
*/ | ||
public DateSerializer() { | ||
dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); | ||
dateFormat.setTimeZone(TimeZone.getTimeZone("UTC")); | ||
} | ||
|
||
@Override | ||
public JsonElement serialize(Date date, Type type, JsonSerializationContext context) { | ||
return new JsonPrimitive(dateFormat.format(date)); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
- Fix the date format output when using the HTTP API to use iso8601 format (bsc#1227543) |