“Java objeto para JSON” Respostas de código

objeto JavaScript para JSON

var person={"first_name":"Tony","last_name":"Hawk","age":31};
var personJSONString=JSON.stringify(person); 
Grepper

JS JSON para objetar

var jsonPerson = '{"first_name":"billy", "age":23}';
var personObject = JSON.parse(jsonPerson); //parse json string into JS object
Grepper

Java objeto para JSON

import com.fasterxml.jackson.databind.ObjectMapper; 
import com.fasterxml.jackson.databind.ObjectWriter; 

ObjectWriter ow = new ObjectMapper().writer().withDefaultPrettyPrinter();
String json = ow.writeValueAsString(object);
Talented Trout

JSON TO Java Objeto

String json = "...";
ObjectMapper m = new ObjectMapper();
Set<Product> products = m.readValue(json, new TypeReference<Set<Product>>() {});
Pleasant Puma

converter objeto java em json

User u = new User();
u.firstName = "Sample";
u.lastName = "User";
u.email = "[email protected]";

ObjectMapper mapper = new ObjectMapper();
    
try {
    // convert user object to json string and return it 
    return mapper.writeValueAsString(u);
}
catch (JsonGenerationException | JsonMappingException  e) {
    // catch various errors
    e.printStackTrace();
}
Cooperative Chimpanzee

converter objeto java em json

public class Student {
	
	Integer id;
	Map<String,Integer> marks;
	List<Address> addresses;
	
	public Student(Integer id, Map<String, Integer> marks, List<Address> addresses) {
		this.id = id;
		this.marks = marks;
		this.addresses = addresses;
	}
}

class Address {
	
	String addrType;
	Integer houseNo;
	String streetName;
	String countryName;
	House house;
	
	public Address(String addrType, Integer houseNo, String streetName, String countryName, House house) {
		this.addrType = addrType;
		this.houseNo = houseNo;
		this.streetName = streetName;
		this.countryName = countryName;
		this.house = house;
	}	
}

class House {
	
	Integer noOfRooms;
	String houseType;
	Integer noOfWindows;
	
	public House(Integer noOfRooms, String houseType, Integer noOfWindows) {
		this.noOfRooms = noOfRooms;
		this.houseType = houseType;
		this.noOfWindows = noOfWindows;
	}
}
ABHIJEET K BEHERA

Respostas semelhantes a “Java objeto para JSON”

Perguntas semelhantes a “Java objeto para JSON”

Mais respostas relacionadas para “Java objeto para JSON” em JavaScript

Procure respostas de código populares por idioma

Procurar outros idiomas de código