• Carlos Manuel Lozano Soto
  • NEWBIE
  • 5 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies

Hi guys,
¿How can I parse a string json with a complex attribute name "_id"?

I'm trying to parse the next json:

 

[{"_id":"55d66226726b611100aaf741","replacement":false,"quantity":5,"name":"Generator 1000 kW","maintenanceperiod":365,"lifespan":120,"cost":5000,"sku":"100003"},{"_id":"55d66226726b611100aaf742","replacement":true,"quantity":183,"name":"Cooling Fan","maintenanceperiod":0,"lifespan":0,"cost":300,"sku":"100004"}]
The Class that I created is:
 
public class Equipment {
    public final String id;
    public final Boolean replacement;
    public final Integer quantity;
    public final String name;
    public final Integer maintenanceperiod;
    public final Integer lifespan;
    public final Integer cost;
    public final Integer sku;

    public Equipment(String id, Boolean replacement, Integer quantity, String name, Integer maintenanceperiod, Integer lifespan, Integer cost, Integer sku) {
        this.id = id;
        this.replacement = replacement;
        this.quantity = quantity;
        this.name = name;
        this.maintenanceperiod = maintenanceperiod;
        this.lifespan = lifespan;
        this.cost = cost;
        this.sku = sku;
    }
}

But I'm having troubles to parse _id from origin string json to Apex code.
 
System.assertEquals('55d66226726b611100aaf741', equipments.get(0).id);

When I try to get the id, only I can obtain null value.

Thanks for your time.
Best Regards, 
Carlos Lozano.

 

Hi guys,
¿How can I parse a string json with a complex attribute name "_id"?

I'm trying to parse the next json:

 

[{"_id":"55d66226726b611100aaf741","replacement":false,"quantity":5,"name":"Generator 1000 kW","maintenanceperiod":365,"lifespan":120,"cost":5000,"sku":"100003"},{"_id":"55d66226726b611100aaf742","replacement":true,"quantity":183,"name":"Cooling Fan","maintenanceperiod":0,"lifespan":0,"cost":300,"sku":"100004"}]
The Class that I created is:
 
public class Equipment {
    public final String id;
    public final Boolean replacement;
    public final Integer quantity;
    public final String name;
    public final Integer maintenanceperiod;
    public final Integer lifespan;
    public final Integer cost;
    public final Integer sku;

    public Equipment(String id, Boolean replacement, Integer quantity, String name, Integer maintenanceperiod, Integer lifespan, Integer cost, Integer sku) {
        this.id = id;
        this.replacement = replacement;
        this.quantity = quantity;
        this.name = name;
        this.maintenanceperiod = maintenanceperiod;
        this.lifespan = lifespan;
        this.cost = cost;
        this.sku = sku;
    }
}

But I'm having troubles to parse _id from origin string json to Apex code.
 
System.assertEquals('55d66226726b611100aaf741', equipments.get(0).id);

When I try to get the id, only I can obtain null value.

Thanks for your time.
Best Regards, 
Carlos Lozano.

 

Hi guys,
¿How can I parse a string json with a complex attribute name "_id"?

I'm trying to parse the next json:

 

[{"_id":"55d66226726b611100aaf741","replacement":false,"quantity":5,"name":"Generator 1000 kW","maintenanceperiod":365,"lifespan":120,"cost":5000,"sku":"100003"},{"_id":"55d66226726b611100aaf742","replacement":true,"quantity":183,"name":"Cooling Fan","maintenanceperiod":0,"lifespan":0,"cost":300,"sku":"100004"}]
The Class that I created is:
 
public class Equipment {
    public final String id;
    public final Boolean replacement;
    public final Integer quantity;
    public final String name;
    public final Integer maintenanceperiod;
    public final Integer lifespan;
    public final Integer cost;
    public final Integer sku;

    public Equipment(String id, Boolean replacement, Integer quantity, String name, Integer maintenanceperiod, Integer lifespan, Integer cost, Integer sku) {
        this.id = id;
        this.replacement = replacement;
        this.quantity = quantity;
        this.name = name;
        this.maintenanceperiod = maintenanceperiod;
        this.lifespan = lifespan;
        this.cost = cost;
        this.sku = sku;
    }
}

But I'm having troubles to parse _id from origin string json to Apex code.
 
System.assertEquals('55d66226726b611100aaf741', equipments.get(0).id);

When I try to get the id, only I can obtain null value.

Thanks for your time.
Best Regards, 
Carlos Lozano.