Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Constructor not defined: [Object].<Constructor>(System.JSONParser) #24

Open
textual opened this issue Aug 17, 2017 · 4 comments
Open

Constructor not defined: [Object].<Constructor>(System.JSONParser) #24

textual opened this issue Aug 17, 2017 · 4 comments

Comments

@textual
Copy link

textual commented Aug 17, 2017

I'm trying to use this for Shopify Orders and a few things are falling into this Object category which results in not being able to save since an object constructor doesn't seem to be valid. Any advice on working around these issues?

@superfell
Copy link
Owner

Do you have more info, a sample json that causes an issue?

@textual
Copy link
Author

textual commented Aug 17, 2017

ShopifyOrder_Error (2).zip
resulting zip file

I used this tool a few months back for what is currently running and had to make quite a few mods to get it to save correctly. It works for about 70% of the data were trying to pull back but now that I'm trying to increase that success rate, I'd like to understand what's going on with some of the anomalies that needed to be addressed for original deployment. Attached is large json of orders from Shopify.

RT_Shopify_Sample.json.zip

@superfell
Copy link
Owner

The issue mentioned in the title here is fixed, however there are other issues with the shopify sample that aren't fixed. [seem to be hitting some kind of expr size limit].

@tpiechota
Copy link

tpiechota commented Feb 10, 2020

I have the same or similar issue. Constructor not defined: [BookingsWrapper.Errors].<Constructor>(JsonParser)
Here is a sample - largely reduced - json2apex outcome

`//
// Generated by JSON2Apex http://json2apex.herokuapp.com/
//
// The supplied json has fields with names that are not valid in apex
// and so can only be parsed with explicitly generated code, this option
// was auto selected for you.

public class BookingsWrapper {

public class Miscellaneous {
	public Integer id {get;set;} 
	public List<Place> place {get;set;} 
	public String resort {get;set;} 
	public String name {get;set;} 
	public String information {get;set;} 
	public List<CreditCards> customFields {get;set;} 

	public Miscellaneous(JSONParser parser) {
		while (parser.nextToken() != System.JSONToken.END_OBJECT) {
			if (parser.getCurrentToken() == System.JSONToken.FIELD_NAME) {
				String text = parser.getText();
				if (parser.nextToken() != System.JSONToken.VALUE_NULL) {
					if (text == 'id') {
						id = parser.getIntegerValue();
					} else if (text == 'place') {
						place = arrayOfPlace(parser);
					} else if (text == 'resort') {
						resort = parser.getText();
					} else if (text == 'name') {
						name = parser.getText();
					} else if (text == 'information') {
						information = parser.getText();
					} else if (text == 'customFields') {
						customFields = arrayOfCreditCards(parser);
					} else {
						System.debug(LoggingLevel.WARN, 'Miscellaneous consuming unrecognized property: '+text);
						consumeObject(parser);
					}
				}
			}
		}
	}
}

[...]

public BookingsWrapper(JSONParser parser) {
	while (parser.nextToken() != System.JSONToken.END_OBJECT) {
		if (parser.getCurrentToken() == System.JSONToken.FIELD_NAME) {
			String text = parser.getText();
			if (parser.nextToken() != System.JSONToken.VALUE_NULL) {
				if (text == 'channel') {
					channel = parser.getIntegerValue();
				} else if (text == 'language') {
					language = parser.getText();
				} else if (text == 'timeStamp') {
					timeStamp = parser.getText();
				} else if (text == 'success') {
					success = parser.getBooleanValue();
				} else if (text == 'bookings') {
					bookings = arrayOfBookings(parser);
				} else {
					System.debug(LoggingLevel.WARN, 'BookingsWrapper consuming unrecognized property: '+text);
					consumeObject(parser);
				}
			}
		}
	}
}	

public static BookingsWrapper parse(String json) {
	System.JSONParser parser = System.JSON.createParser(json);
	return new BookingsWrapper(parser);
}


private static List<CreditCards> arrayOfCreditCards(System.JSONParser p) {
    List<CreditCards> res = new List<CreditCards>();
    if (p.getCurrentToken() == null) p.nextToken();
    while (p.nextToken() != System.JSONToken.END_ARRAY) {
        res.add(new CreditCards(p));
    }
    return res;
}

}`

While I was trying to solve it I also came across the following exception:
Illegal assignment from System.JSONParser to JsonParser

So to solve the issue I added System. to every sub class constructor, ie:
public Miscellaneous(System.JSONParser parser) {}
public BookingsWrapper(System.JSONParser parser) {}

That worked form me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants