logo
down
shadow

Serialization for Java Calendar


Serialization for Java Calendar

By : ポストルウェートカイル
Date : November 22 2020, 02:42 PM
like below fixes the issue From JSON to Calendar
Create a JsonSerializer:
code :
public class CalendarSerializer extends JsonSerializer<Calendar> {

    private SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yyyy");

    @Override
    public void serialize(Calendar calendar, JsonGenerator jsonGenerator,
                          SerializerProvider serializerProvider) throws IOException {

        String dateAsString = formatter.format(calendar.getTime());
        jsonGenerator.writeString(dateAsString);

    }
}
@JsonSerialize(using = CalendarSerializer.class)
private Calendar calendar;
public class CalendarDeserializer extends JsonDeserializer<Calendar> {

    private SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yyyy");

    @Override
    public Calendar deserialize(JsonParser jsonParser,
                                DeserializationContext deserializationContext) 
                                throws IOException {

        String dateAsString = jsonParser.getText();

        try {
            Date date = formatter.parse(dateAsString);
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(date);
            return calendar;
        } catch (Exception e) {
            throw new IOException(e);
        }
    }
@JsonDeserialize(using = CalendarDeserializer.class)
private Calendar calendar;


Share : facebook icon twitter icon
Java Calendar.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY), will it roll backwards, forwards or unknown?

Java Calendar.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY), will it roll backwards, forwards or unknown?


By : user1413086
Date : March 29 2020, 07:55 AM
wish helps you It should always keep the same WEEK_OF_MONTH (http://java.sun.com/j2se/1.4.2/docs/api/java/util/Calendar.html#WEEK_OF_MONTH). From the documentation:
What is the difference between Calendar.WEEK_OF_MONTH and Calendar.DAY_OF_WEEK_IN_MONTH in Java's Calendar class?

What is the difference between Calendar.WEEK_OF_MONTH and Calendar.DAY_OF_WEEK_IN_MONTH in Java's Calendar class?


By : user3247965
Date : March 29 2020, 07:55 AM
I wish did fix the issue. Week of Month is the week within the current month starting from sundays how many weeks have there been.
Day of week of month is the day 5 would be Thursday, 1 sunday ect.
calendar serialization deserialization

calendar serialization deserialization


By : Sandesh Chauhan
Date : March 29 2020, 07:55 AM
This might help you Date represents a point in time (number of milliseconds from 1st of January 1970). Do not be confused by the time zone in Date.toString(), you are always serializing long value wrapped in a class.
Calendar on the other hand represents date and time in given time zone. This means that if the source computer is in GMT+1 and the target one in the GMT+2, but you are sending Calendar set to GMT-6, it will be GMT-6 all the way on both sides.
In java.util.Calendar, why does setting the value of Calendar.YEAR affect the value of Calendar.MONTH?

In java.util.Calendar, why does setting the value of Calendar.YEAR affect the value of Calendar.MONTH?


By : Cunnie
Date : March 29 2020, 07:55 AM
should help you out I believe the calendar is remembering how many days into the year you are. in 2012 you were on day 31 + 29 = Feb 29. In 2011 that was March 1. Then you asked for the actual maximum of that month, which (for March) is 31.
Calendar API is horrible.
Android Calendar Serialization Incompatible with Java 6

Android Calendar Serialization Incompatible with Java 6


By : user5992271
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further
I am attempting to use an object serialization socket connection between a Java server and an Android client
Related Posts Related Posts :
  • IntelliJ - include pom.xml dependencies in lib directory
  • Tomcat 7 : Filtering lifecycle events
  • JSONException: Names must be strings
  • Build Spark JavaRDD List from DropResult objects
  • Include css file in richlet with zk
  • Jackson CSV's WRAP_AS_ARRAY
  • Priority for a web request in Java web applications
  • Is there a better way to format this timestamp to ISO8601?
  • Issue with Spring Scope
  • How to declare and use an array of dictionaries from Python in Java and filter them?
  • Wrong weekdays from Calendar.getDisplayName()
  • ClassNotFoundException when creating new ClassPathXmlApplicationContext
  • Java Method Call from Thread
  • Remove background noise from image to make text more clear for OCR
  • PostgreSQL query always return true
  • How to connect FX controller with main app
  • Is there a difference between these two code snippets, and if so what?
  • When two interfaces have conflicting return types, why does one method become default?
  • Updating database throws errors in To Do List app
  • Where does the url come from?
  • Dagger 2 issue overriding single provides annotated method from a module in a library which app uses
  • Better way then If(x instanceof y) in Java?
  • how to debug maven enunciate plugin tomcat web service
  • Spring Context Initialization fails when upgrading to version 4.2.3
  • spring boot cannot connect to rabbitmq
  • How to Run Unit Test in Parallel Across All Modules Using Maven?
  • Getting the next Value in a ArrayList(Not working)
  • How to wait for a MouseListener mouse press?
  • Java RMI: Blocking for void method return?
  • Get Table Properties out of Hive using Java API
  • Read CSV file and write to another CSV - ArrayIndexOutOfBoundsException and pattern difficuties
  • Set LineChart(javafx) style to a child element
  • ArrayList how catch exception on one item from constructor
  • java.lang.NumberFormatException: For input string: " 1"
  • Dekker's Algorithm not working fine for three processes
  • Maven javadoc plugin - package does not exist
  • NotOLE2FileException: Invalid header signature; read 0x0000000000000000, expected 0xE11AB1A1E011CFD0
  • NullPointerExcpetion on findViewById
  • Java ArrayList initialization
  • Problems on making a Tic Tac Toe Game in Java
  • how to set proxy server details on WebServiceTemplate
  • How can I get a Class object form primitive?
  • How to count rows and Columns of excel sheet in Java
  • Should I split up texture atlas?
  • JavaFX freezing issue
  • What is the JavaFX equivalent of androids AsyncTask?
  • Zenity bash command not working with Java
  • GSON serialize multiple properties to sub object
  • How to convert some elements that satisfy a particular condition in a 2d array into a list in java?
  • Setting LinkedList nodes to null
  • Java Swing ignore text size on JButton
  • Collision detection for separate class instances - Processing Java
  • handle unreal numbers, jump to catch
  • Java - 100 decimal places in variable
  • Cancel previously shown toast before showing new toast
  • projectile motion sim - 'illegal start of type' error
  • How to print out the whole contents of a stack?
  • How to find variable name from a list of class in a package
  • how can i make this dialog close when socket is accepted?
  • I have created a small book program, I am new to java. Can't find what the error or mistake in this code?
  • shadow
    Privacy Policy - Terms - Contact Us © animezone.co