Android                
            Jackson
        
        
            
    Szukaj…
Wprowadzenie
Jackson to uniwersalna biblioteka Java do przetwarzania JSON. Jackson dąży do tego, aby być najlepszym możliwym połączeniem szybkiego, poprawnego, lekkiego i ergonomicznego dla programistów.
Funkcje Jacksona :
Tryb wieloprzetwarzania i bardzo dobra współpraca
Nie tylko adnotacje, ale także adnotacje mieszane
W pełni obsługuje typy ogólne
Obsługuje typy polimorficzne
Przykład pełnego powiązania danych
Dane JSON
{
  "name" : { "first" : "Joe", "last" : "Sixpack" },
  "gender" : "MALE",
  "verified" : false,
  "userImage" : "keliuyue"
}
 Aby zmienić ją w instancję użytkownika, potrzeba dwóch linii Java:
ObjectMapper mapper = new ObjectMapper(); // can reuse, share globally
User user = mapper.readValue(new File("user.json"), User.class);
 Klasa użytkownika
public class User {
    public enum Gender {MALE, FEMALE};
    public static class Name {
        private String _first, _last;
        public String getFirst() {
            return _first;
        }
        public String getLast() {
            return _last;
        }
        public void setFirst(String s) {
            _first = s;
        }
        public void setLast(String s) {
            _last = s;
        }
    }
    private Gender _gender;
    private Name _name;
    private boolean _isVerified;
    private byte[] _userImage;
    public Name getName() {
        return _name;
    }
    public boolean isVerified() {
        return _isVerified;
    }
    public Gender getGender() {
        return _gender;
    }
    public byte[] getUserImage() {
        return _userImage;
    }
    public void setName(Name n) {
        _name = n;
    }
    public void setVerified(boolean b) {
        _isVerified = b;
    }
    public void setGender(Gender g) {
        _gender = g;
    }
    public void setUserImage(byte[] b) {
        _userImage = b;
    }
}
 Marshalling z powrotem do JSON jest podobnie prosty:
mapper.writeValue(new File("user-modified.json"), user);
    
    
    
    
    Modified text is an extract of the original Stack Overflow Documentation
        Licencjonowany na podstawie CC BY-SA 3.0
        Nie związany z Stack Overflow