Programming Articles - Page 2332 of 3366

How to convert the JSON object to a bean using JSON-lib API in Java?

raja
Updated on 08-Jul-2020 11:34:52

4K+ Views

The JSONObject class is a collection of name/value pairs (unordered) where the bean is a class with setter and getter methods for its member fields. We can convert a JSON object to a bean using the toBean() method of JSONObject class.Syntaxpublic static Object toBean(JSONObject jsonObject, Class beanClass)Exampleimport net.sf.json.JSONObject; public class ConvertJSONObjToBeanTest {    public static void main(String[] args) {       mployee emp = new Employee("Sai", "Ram", 30, "Bangalore");       JSONObject jsonObj = JSONObject.fromObject(emp);       System.out.println(jsonObj.toString(3)); // pretty print JSON       emp = (Employee)JSONObject.toBean(jsonObj, Employee.class);       System.out.println(emp.toString());    }    // Employee class    public static ... Read More

Importance of @JsonFilter annotation in Java?

Manisha Chand
Updated on 20-May-2025 19:02:42

1K+ Views

The @JsonFilter annotation belongs to Jackson Annotations. Jackson Annotations are used during serialization and deserialization to denote a particular field (or method) that is declared in Java as an instance variable, is a JsonProperty, and should be ignored, or what condition should be applied to it. It is used to define a dynamic filter for serializing/deserializing Java objects. @jsonfilter annotation Let's discuss the importance of jsonfilter annotation as given below - It is used to filter which fields or properties of an object should be included ... Read More

Double.ToString Method in C#

AmitDiwan
Updated on 07-Nov-2019 07:31:15

198 Views

The Double.ToString() method in C# is used to convert the numeric value of this instance to its equivalent string representation.SyntaxFollowing is the syntax −public override string ToString ();ExampleLet us now see an example to implement the Double.ToString() method −using System; public class Demo{    public static void Main(){       double d = 45.7878d;       string str = d.ToString();       Console.WriteLine("String = "+str);    } }OutputThis will produce the following output −String = 45.7878ExampleLet us now see another example −using System; public class Demo{    public static void Main(){       double d = ... Read More

Console.Clear Method in C#

AmitDiwan
Updated on 07-Nov-2019 07:27:24

197 Views

The Console.Clear method in C# is used to clear the console buffer and corresponding console window of display information.SyntaxFollowing is the syntax −public static void Clear ();ExampleLet us now see an example before implementing the Console.Clear method −using System; public class Demo {    public static void Main(){       Uri newURI1 = new Uri("https://www.tutorialspoint.com/");       Console.WriteLine("URI = "+newURI1);       Console.WriteLine("String representation = "+newURI1.ToString());       Uri newURI2 = new Uri("https://www.tutorialspoint.com/jquery.htm#abcd");       Console.WriteLine("URI = "+newURI2);       Console.WriteLine("String representation = "+newURI2.ToString());       if(newURI1.Equals(newURI2))          Console.WriteLine("Both the ... Read More

Uri.ToString() Method in C#

AmitDiwan
Updated on 07-Nov-2019 07:24:49

214 Views

The Uri.ToString() method in C# is used to get a canonical string representation for the specified Uri instance.SyntaxFollowing is the syntax −public override string ToString ();ExampleLet us now see an example to implement the Uri.ToString() method −using System; public class Demo {    public static void Main(){       Uri newURI1 = new Uri("https://www.tutorialspoint.com/");       Console.WriteLine("URI = "+newURI1);       Console.WriteLine("String representation = "+newURI1.ToString());       Uri newURI2 = new Uri("https://www.tutorialspoint.com/jquery.htm#abcd");       Console.WriteLine("URI = "+newURI2);       Console.WriteLine("String representation = "+newURI2.ToString());       if(newURI1.Equals(newURI2))          Console.WriteLine("Both the URIs ... Read More

Uri.MakeRelativeUri(Uri) Method in C#

AmitDiwan
Updated on 07-Nov-2019 07:22:50

198 Views

The Uri.MakeRelativeUri(Uri) method in C# is used to determine the difference between two Uri instances.SyntaxFollowing is the syntax −public Uri MakeRelativeUri (Uri uri);Above, the URI is the URI to compare to the current URI.ExampleLet us now see an example to implement the Uri.MakeRelativeUri(Uri) method −using System; public class Demo {    public static void Main(){       Uri newURI1 = new Uri("https://www.tutorialspoint.com/");       Console.WriteLine("URI = "+newURI1);       Uri newURI2 = new Uri("https://www.tutorialspoint.com/java.htm");       Console.WriteLine("URI = "+newURI2);       if(newURI1.Equals(newURI2))          Console.WriteLine("Both the URIs are equal!");       else ... Read More

DateTime.FromFileTimeUtc() Method in C#

AmitDiwan
Updated on 07-Nov-2019 07:20:43

195 Views

The DateTime.FromFileTimeUtc() method in C# converts the specified Windows file time to an equivalent UTC time.SyntaxFollowing is the syntax −public static DateTime FromFileTimeUtc (long time);Here, the parameter time is the Windows file time expressed in ticks (expressed in 100-nanosecond ticks.)ExampleLet us now see an example to implement the DateTime.FromFileTimeUtc() method −using System; public class Demo {    public static void Main() {       DateTime d1 = DateTime.FromFileTimeUtc(6500000000000);       System.Console.WriteLine("DateTime = {0:dd} {0:y}, {0:hh}:{0:mm}:{0:ss} ", d1);    } }OutputThis will produce the following output −DateTime = 08 January 1601, 12:33:20ExampleLet us now see another example to implement ... Read More

DateTime.FromFileTime() Method in C#

AmitDiwan
Updated on 07-Nov-2019 07:19:10

159 Views

The DateTime.FromFileTime() method in C# is used to convert the specified Windows file time to an equivalent local time.SyntaxFollowing is the syntax −public static DateTime FromFileTime (long fileTime);Above, the parameter lifetime is a Windows file time expressed in ticks.ExampleLet us now see an example to implement the DateTime.FromFileTime() method −using System; public class Demo {    public static void Main() {       DateTime d1 = DateTime.FromFileTime(100000000000);       System.Console.WriteLine("DateTime = {0:dd} {0:y}, {0:hh}:{0:mm}:{0:ss} ", d1);    } }OutputThis will produce the following output −DateTime = 01 January 1601, 02:46:40ExampleLet us now see another example to implement the ... Read More

DateTime.FromBinary() Method in C#

AmitDiwan
Updated on 07-Nov-2019 07:15:54

258 Views

The DateTime.FromBinary() method in C# is used to deserialize a 64-bit binary value and recreates an original serialized DateTime object.SyntaxFollowing is the syntax −public static DateTime FromBinary (long val);Above, Val is a 64-bit signed integer that encodes the Kind property in a 2-bit field and the Ticks property in a 62-bit field.ExampleLet us now see an example to implement the DateTime.FromBinary() method −using System; public class Demo {    public static void Main() {       DateTime d1 = new DateTime(2019, 11, 10, 6, 20, 45);       long val = d1.ToBinary();       DateTime d2 = ... Read More

DateTime.Equals() Method in C#

AmitDiwan
Updated on 07-Nov-2019 07:12:51

2K+ Views

The DateTime.Equals() method in C# is used check whether two DateTime objects or instances are equal or not. TRUE is returned if both are equal, else FALSE would be the return value.SyntaxFollowing is the syntax −public static bool Equals (DateTime date1, DateTime date2);ExampleLet us now see an example to implement the DateTime.Equals() method −using System; public class Demo {    public static void Main() {       DateTime d1 = new DateTime(2019, 09, 10, 5, 15, 25);       DateTime d2 = d1.AddMonths(25);       Console.WriteLine("Initial DateTime = {0:dd} {0:y}, {0:hh}:{0:mm}:{0:ss} ", d1);       Console.WriteLine("New ... Read More

Advertisements