x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

How to stop case correction when converting from Struct to JSON in Packaged Build?

Have a custom struct I'm trying to convert to JSON. It successfully converts to JSON with the correct capitalization (matching the variable names of the struct) in the editor, but the capitalization on the variable names gets corrected in a packaged build, which messes up the API I'm using.

For example, the struct variable name is "userID", which is what the API expects, but when I use the UE4 methods to serialize the struct into JSON the variable name becomes "UserId" which makes the JSON object not work with the API.

I found in the JsonObjectConverter::UStructToJsonAttributes that there's a line that calls StandarizeCase(Property->GetName()), so I made a custom version of this function and removed this line but it didn't solve the problem. In fact, I traced the problem through debugging to when it begins iterating through the uproperties of the struct. It seems to think the variable names are capitalized a different way from the start of iteration when passed the ustruct type.

Furthermore, it doesn't capitalize all variable names. Here are some of the variable names and what they print out as in a packaged build (all names are correct in-editor):

  • var name -> becomes this

  • userID -> UserId

  • sessionID -> SessionId

  • eventName -> EventName

  • eventTimestamp -> eventTimestamp (no change)

  • eventParams -> eventParams (no change)

Also, names inside the tmap called "eventParams" don't seem to change. I send the events to the API and can confirm that there's no issue with misprinting to the console as the API confirms the names have changed as listed above.

I'm highly suspicious of the FNames assigned to these variables. I believe the FNames are saved somewhere as "UserId" for example and even though I changed it to "userID" in code. According to this question Fnames became case sensitive in 4.5 which in theory should be good but I'm not seeing the change reflected.

I've tried completely removing the struct and all functions related to it, deleting the Intermediate and Saved folders, and rebuilding and packaging without the struct, then adding them back in but the fnames seem to still be retained!

I'm currently building a struct to JSON converter from scratch to avoid this issue, but figured I'd ask to see if anybody else has had this issue or knows if I'm doing something wrong or how to get around it. Again, the whole thing works as-is in editor and standalone, just packaged builds are the problem. Any help is greatly appreciated.

Here is my struct:

 USTRUCT()
 struct FDelta_Event {
     GENERATED_BODY()
     UPROPERTY() FString eventName;
     UPROPERTY() FString userID;    
     UPROPERTY() FString sessionID;    
     UPROPERTY() FString eventTimestamp;                        
     UPROPERTY() TMap<FString, FString> eventParams;
 
     FDelta_Event() {
         FDateTime currentTime = FDateTime::Now();
 // manually convert currentTime into API format Format: yyyy-MM-dd HH:mm:ss.SSS
 // with a bunch of ifs and eventTimestamp.AppendInt()s
 
         if ( PLATFORM_WINDOWS )
         {
             eventParams.Add( "platform", "WINDOWS_DESKTOP" );
         }
         else if ( PLATFORM_XBOXONE )
         {
             eventParams.Add( "platform", "XBOXONE" );
         }
         else
         {
             eventParams.Add( "platform", "UNKNOWN" );
         }
         eventParams.Add( "sdkVersion", "CustomSDK" );
     }
 };

Here is the the templated function I would like to call:

 template <typename StructType>
 void UHttpService::GetJsonStringFromStruct( StructType filledStruct, FString& stringOutput )
 {
     UStructToJsonObjectString( StructType::StaticStruct(), &filledStruct, stringOutput, 0, 0 );
 }

Product Version: UE 4.20
Tags:
more ▼

asked Jun 04 '19 at 01:30 PM in C++ Programming

avatar image

LastOfRamoria
1 1 2

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

0 answers: sort voted first
Be the first one to answer this question
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question