Parsing JIRA, Now parsing JSON with dynamic using Newtonsoft fails



  • @Onyx said:

    Agreed, but there's pretty much no way to do that with a generic library is what I'm saying, object implementation is still up to you. I guess you could make something that creates a class with generic getters and setters, but that's as far an off-the shelf solution could go.

    This is supposed to be possible, but just didn't work.
    Again, officially supported, but didn't work at all.


  • Java Dev

    Huh? You nest them.

    Have a generic object that can be an object, array, string, number, boolean, or null. Store each of those as appropriate, and recurse. Took me about a day and 1kloc in C from scratch.




  • BINNED

    @PleegWat said:

    Huh? You nest them.

    Have a generic object that can be an object, array, string, number, boolean, or null. Store each of those as appropriate, and recurse. Took me about a day and 1kloc in C from scratch.

    Oh, sorry, we're talking about different things. Yes, that works out of the box: Objects get converted to QMap<QString, QVariant>, arrays get converted to QList<QVariant>, where QVariant is a generic container that can store primitives and other containers.

    I was talking about automatic mapping to custom classes as being out of scope of generic libraries. In my case, I grab notifications JSON from Discourse and map it to my own notification class.


  • Java Dev

    Ah, yeah. You pretty much end up having to do that mapping one way or another. I've got a couple of nested/recursive functions that send it straight back to string. As mentioned, rules engine, we barely use the stuff direct.


  • Discourse touched me in a no-no place

    @Onyx said:

    I was talking about automatic mapping to custom classes as being out of scope of generic libraries.

    There are some libraries that can do that sort of thing in Java (guided by standard JAXB annotations). I don't really recommend them. The pain is rather less if you just accept that JSON doesn't fit very well with very strongly typed languages, and use a data format that matches what is in the JSON itself.



  • @dkf said:

    data format that matches what is in the JSON itself.

    Hmm... looks like it's all strings.
    Strings should work.


  • BINNED

    @dkf said:

    The pain is rather less if you just accept that JSON doesn't fit very well with very strongly typed languages, and use a data format that matches what is in the JSON itself.

    Tell me about it... I have this idiocy:

    // QJson will convert all numbers into doubles. Cast them to ints if possible
    // This is needed to cast to enums properly, attempting to use a double in enum WRITE function
    // will always result in a 0 value
    if(i.value().type() == QVariant::Double)
    {
        if(i.value().toInt(&conversionOk) == i.value().toDouble(&conversionOk))
        {
            this->setProperty(key.toStdString().c_str(), i.value().toInt(&conversionOk));
            continue;
        }
    }
    
    // Let QVariant automatically cast any other types
    if(!this->setProperty(key.toStdString().c_str(), i.value()))
    {
        qDebug() << "Couldn't set property" << key << "to value" << i.value();
    }
    

    Which is... hacky and very error prone. But it works for the limited usecase it's intended to cover. For now. I can always just override it other classes. Or maybe scrap it altogether, I'll see, didn't test with enough different input values yet



  • @blakeyrat said:

    You're supposed to serialize into a predefined object, but that assumes a single party owns both server and client and I've never worked in a place where that was the case.

    @Onyx said:

    Agreed, but there's pretty much no way to do that with a generic library is what I'm saying, object implementation is still up to you. I guess you could make something that creates a class with generic getters and setters, but that's as far an off-the shelf solution could go.

    You can do strongly-typed deserialization without control of both sides. Your program will depend on the JSON message being in a certain format. Just because you deserialize into a map doesn't mean that the message can change and your code will figure out what to do.

    There is not much difference between

    var jsonmsg = JSONLibrary.DeserializeAsMap(jsonstring);
    DoSomething(jsonmsg["FirstName"], jsonmsg["LastName"]);
    

    ... and ...

    class SomeJSONMessage
    {
      public string FirstName {get; set;}
      public string LastName {get; set;}
    }
    
    var jsonmsg = JSONLibrary.DeserializeAsClass<SomeJSONMessage>(jsonstring);
    DoSomething(jsonmsg.FirstName, jsonmsg.LastName);
    

    Both are equally fragile if the other party changes the message. I would argue that the second form is better if the message changes. Once you figure out the new format and fix the class, the strong typing will tell you all of the down-stream implications.



  • @Onyx said:

    Tell me about it... I have this idiocy:

    That's horrible. It looks to me like you can't depend on the data type you will get back from it. You could get ints for the first six months of production because by some freak chance, a field always has whole integer amounts in it, even though it could have a decimal in it. At some point in the future, your code may stop working.

    I can't imagine what you would lose by always returning a Double when the value is unquoted. The auto-detection it's doing doesn't seem to be a good thing.


  • Discourse touched me in a no-no place

    @Jaime said:

    I would argue that the second form is better if the message changes. Once you figure out the new format and fix the class, the strong typing will tell you all of the down-stream implications.

    Two words: JSON Schema. Another word: Bleugh.


  • BINNED

    @Jaime said:

    That's horrible. It looks to me like you can't depend on the data type you will get back from it.

    It's from Discourse. Of course I can't depend on it. Really, I think I'll have more problems with shit breaking all around than data type.

    @Jaime said:

    I can't imagine what you would lose by always returning a Double when the value is unquoted. The auto-detection it's doing doesn't seem to be a good thing.

    Because I have this silly notion that this:

    enum QDiscourseNotificationType { 
        Invalid,
        Mentioned,
        Replied,
        Quoted,
        Edited,
        Liked,
        PrivateMessage,
        InvitedToPrivateMessage,
        InviteeAccepted,
        Posted,
        MovedPost,
        Linked
        GrantedBadg
     };
    

    Makes more sense than having a bunch of hardcoded ints. And, unfortunately, setProperty is not smart enough to cast from double to enum automatically.


    Filed under: Fucking hell, why can't Discourse highlight enums?


  • Discourse touched me in a no-no place

    @Onyx said:

    GrantedBadger

    FTFY


  • BINNED

    Change approved for the special "TDWTF edition" of the library.


  • ♿ (Parody)


  • BINNED

    @Onyx said:

    No, don't post links, I really don't want to know. Running out of brain bleach.

    CAN'T YOU PEOPLE READ?


  • FoxDev

    @Onyx said:

    No, don't post links, I really don't want to know. Running out of brain bleach.

    more is on the way!



  • @Onyx said:

    Because I have this silly notion that this:

    enum QDiscourseNotificationType {
    Invalid,
    Mentioned,
    Replied,
    Quoted,
    Edited,
    Liked,
    PrivateMessage,
    InvitedToPrivateMessage,
    InviteeAccepted,
    Posted,
    MovedPost,
    Linked
    GrantedBadg
    };

    Makes more sense than having a bunch of hardcoded ints. And, unfortunately, setProperty is not smart enough to cast from double to enum automatically.


    But, you know it's an int. Why make a library guess that it's an int rather than a double that just happens to be a whole number (maybe a price field, but everything is whole dollar amounts like a fancy restaurant).



  • @dkf said:

    Two words: JSON Schema. Another word: Bleugh.

    I know JSON Schema exists. But, if used properly, it will simply be used to build a custom deserializer, just like the code I posted.



  • @Onyx said:

    Makes more sense than having a bunch of hardcoded ints.

    The problem is that the enum is defined by the API owner, and if they change the numbering (say by inserting a new item in between Edited and Liked), you're gonna have a cascade of brokenness. You really ought to number that enum.

    BTW the one-pager JSON parser will prefer ints and longs over doubles. So if the API sends an int, your C# code will indeed see an int.


  • BINNED

    @Jaime said:

    Why make a library guess that it's an int rather than a double that just happens to be a whole number (maybe a price field, but everything is whole dollar amounts like a fancy restaurant).

    @Onyx said:

    Which is... hacky and very error prone. But it works for the limited usecase it's intended to cover.

    I'm not writing a general purpose library. It will interface with Discourse and nothing else. All other properties are typed and will get automatlcally cast back to whatever type the property is if needed. As I said, I may scrap it all, but for now it's ok and I don't have to manually cast stuff for every single enum I have. If it turns out to be broken in the future I'll throw that bit away.

    @blakeyrat said:

    The problem is that the enum is defined by the API owner, and if they change the numbering (say by inserting a new item in between Edited and Liked), you're gonna have a cascade of brokenness. You really ought to number that enum.

    Good point, I'll do that. I doubt they will insert stuff in many places tbh since most of the numbering is in the DB (and they would break half the posts if they did), but hey, Discourse!

    @blakeyrat said:

    BTW the one-pager JSON parser will prefer ints and longs over doubles. So if the API sends an int, your C# code will indeed see an int.

    Yeah, can't use it since this is C++. Though I have no idea why the hell they decided to cast everything numeric to double without even checking if it has, you know, a decimal separator.



  • @Onyx said:

    Though I have no idea why the hell they decided to cast everything numeric to double without even checking if it has, you know, a decimal separator.

    The JSON spec. JSON has six types; boolean, null, number, string, array, and object. JavaScript has no int type.



  • @Jaime said:

    The JSON spec. JSON has six types; boolean, null, number, string, array, and object. JavaScript has no int type.

    JavaScript treats its "number" type as ints in certain circumstances and doubles in others. (I don't know the rules off the top of my head. But I do know that 3 + 3 is 6 and not 5.999999999999923 or whatever a double would produce.)

    Since that behavior is not very reproducible in other programming languages, there's nothing wrong with interpreting a JavaScript "number" type as whatever type you think is most convenient.


  • FoxDev

    @blakeyrat said:

    JavaScript treats its "number" type as ints in certain circumstances and doubles in others.

    actually:

    .1 + .2 = 0.30000000000000004
    3 + 3 = 6
    

    try that in any language with IEEE floating point numbers.

    in JS there are only doubles.



  • Oh hey. An "uh, actually" post from Accalia. It's my lucky day.


  • kills Dumbledore

    @accalia said:

    in JS there are only doubles.

    That's like the strapline to a new, really boring Games Workshop game

    in the grim darkness of the far future, there is only warIEEE Floating point specification


  • BINNED

    @accalia said:

    in JS there are only doubles.

    So Qt devs were right to do what they did, since scripting in JS is supported out of the box, and you'll presumably handle a lot of JSON because of that...

    Well, fuck them being right, I'd still prefer the damned thing trying to cast to int if there's no decimal separator in the JSON.


  • FoxDev

    what? whole numbers have always added losslessly in IEEE so long as both numbers and their result are in the safe representation range (don't require an exponent to move the decimal point to the right)

    it's decimals that add weird.

    that's just the IEEE floating point number spec.


  • FoxDev

    @accalia said:

    decimal pint

    That would be 568 millilitres, yes?


  • FoxDev

    nein!

    it's 568.0000000000000000000000000000001 millilitres!



  • @accalia said:

    what? whole numbers have always added losslessly in IEEE so long as both numbers and their result are in the safe representation range (don't require an exponent to move the decimal point to the right)

    Look. What the fuck ever.

    The point is, different programming languages treat numbers differently. As long as the number can be parsed and understood by both, it doesn't fucking matter.

    And in cases where the number is mapped to an enum, you need a fucking int in C#. So make it a fucking int.


  • FoxDev

    @blakeyrat said:

    fucking int

    Is that how shorts are made? :rimshot:



  • @blakeyrat said:

    The problem is that the enum is defined by the API owner, and if they change the numbering (say by inserting a new item in between Edited and Liked), you're gonna have a cascade of brokenness. You really ought to number that enum.

    Is this enum data coming directly from Disrouce JSON?

    If not, I'd probably be thinking about serializing/persisting the enum values as strings, at least then you aren't going to be screwed over by renumberings...

    If it is, then fuck, why'd they even bother to have an enum there at all?


  • BINNED

    It's integers in JSON. This is notification JSON for a PM I just sent to @QBot:

        {
            "created_at": "2015-02-21T00:19:49.999Z",
            "data": {
                "display_username": "11 replies",
                "original_post_id": 241295,
                "original_username": "Onyx",
                "topic_title": "Test"
            },
            "notification_type": 6,
            "post_number": 21,
            "read": false,
            "slug": "test",
            "topic_id": 7977
        }
    

    Yes, display_username is not a username at all...

    Actual meaning is stored in database, this is some of it extracted by @accalia:

    notify_types = {
                1: 'mentioned',
                2: 'replied',
                3: 'quoted',
                4: 'edited',
                5: 'liked',
                6: 'private_message',
                7: 'invited_to_private_message',
                8: 'invitee_accepted',
                9: 'posted',
                10: 'moved_post',
                11: 'linked',
                12: 'granted_badge'
            },
            action_types = {
                1: 'bookmark',
                2: 'like',
                3: 'off_topic',
                4: 'inappropriate',
                5: 'vote',
                8: 'spam',
                6: 'notify_user',
                7: 'notify_moderators'
            },
    

    Yes, it's the same for actions.

    Now, if they just had strings I'd keep it that way most likely. With integers, I can either map it to an enum, or map it to an array of strings. Enums turn out to be less work, and easier to modify as needed. But given that this shit is in the DB I hope it will be pretty constant.


  • FoxDev

    @Onyx said:

    But given that this shit is in the DB I hope it will be pretty constant.

    AFAIK there's no way in /admin to change those values so.... probably?



  • @Jaime said:

    The JSON spec. JSON has six types; boolean, null, number, string, array, and object. JavaScript has no int type

    JSON won't even let you store undefined data!



  • @Onyx said:

    What else can you do, really? I can't see a way where you can automatically convert JSON to anything more useful than that.

    Uses reflection with statically linked RTTI. And I have an easy out if I don't want to figure out what the type actually is: just use interface{} or map[string]interface{}.

    @Jaime said:

    Both are equally fragile if the other party changes the message

    Agreed.



  • @Onyx said:

    Actual meaning is stored in database, this is some of it extracted by @accalia:

    And in the source of every page (easily extracted with a simple regex):

    <script>
            PreloadStore.store("site",{"default_archetype":"regular","notification_types":{"mentioned":1,"replied":2,"quoted":3,"edited":4,"liked":5,"private_message":6,"invited_to_private_message":7,"invitee_accepted":8,"posted":9,"moved_post":10,"linked":11,"granted_badge":12},"post_types":{"regular":1,"moderator_action":2},"groups":[{"id":1,"name":"admins"},{"id":51,"name":"area_bel"},{"id":43,"name":"area_deu"},{"id":42,"name":"area_gbr"},{"id":41,"name":"area_usa"},{"id":50,"name":"bots"},{"id":0,"name":"everyone"},{"id":2,"name":"moderators"},{"id":49,"name":"programmers_testers"},{"id":3,"name":"staff"},{"id":52,"name":"super_sekret_group"},{"id":53,"name":"tl4_plus"},{"id":10,"name":"trust_level_0"},{"id":11,"name":"trust_level_1"},{"id":12,"name":"trust_level_2"},{"id":13,"name":"trust_level_3"},{"id":14,"name":"trust_level_4"}],"filters":["latest","unread","new","read","posted","bookmarks"],"periods":["yearly","monthly","weekly","daily"],"top_menu_items":["latest","unread","new","read","posted","bookmarks","category","categories","top"],"anonymous_top_menu_items":["latest","top","categories","category","categories","top"],"uncategorized_category_id":1,"is_readonly":false,"disabled_plugins":[],"categories":[{"id":13,"name":"General","color":"0E76BD","text_color":"000000","slug":"general","topic_count":474,"post_count":91929,"description":"General: This category is designed for topics that do not fit any other categories.","description_text":"General: This category is designed for topics that do not fit any other categories.","topic_url":"/t/about-the-general-discussion-category/235","read_restricted":false,"permission":1,"notification_level":null,"logo_url":"/uploads/default/3723/50acaa61d431f685.png","background_url":""},{"id":3,"name":"Meta","color":"808281","text_color":"000000","slug":"meta","topic_count":431,"post_count":32238,"description":"Meta: Discussion about this forum, its organization, how it works, and how we can improve it.","description_text":"Meta: Discussion about this forum, its organization, how it works, and how we can improve it.","topic_url":"/t/category-definition-for-meta/2","read_restricted":false,"permission":1,"notification_level":null,"logo_url":"/uploads/default/3732/644a849003f8b73d.png","background_url":""},{"id":16,"name":"Bug","color":"f5f577","text_color":"000000","slug":"bug","topic_count":551,"post_count":9913,"description":"Sandbox to experiment and discuss Discourse bugs. No longer (actively) monitored by Discourse developers.","description_text":"Sandbox to experiment and discuss Discourse bugs. No longer (actively) monitored by Discourse developers.","topic_url":"/t/about-the-bug-category/548","read_restricted":false,"permission":1,"parent_category_id":3,"notification_level":null,"logo_url":"/uploads/default/3719/e095e6aa6b09862d.png","background_url":""},{"id":8,"name":"Article","color":"2db8c2","text_color":"000000","slug":"article","topic_count":132,"post_count":9060,"description":"Article Discussion: Topics in this category are designed for discussion pertaining to a specific post on TheDailyWTF.com. ","description_text":"Article Discussion: Topics in this category are designed for discussion pertaining to a specific post on TheDailyWTF.com. ","topic_url":"/t/about-the-article-discussion-category/31","read_restricted":false,"permission":null,"notification_level":null,"logo_url":"/uploads/default/3728/77f08721fbd48a95.png","background_url":""},{"id":10,"name":"Side Bar WTF","color":"c1103b","text_color":"000000","slug":"side-bar-wtf","topic_count":593,"post_count":38510,"description":"Side Bar: Because more things make us ask WTF than just code. ","description_text":"Side Bar: Because more things make us ask WTF than just code. ","topic_url":"/t/about-the-side-bar-wtf-category/37","read_restricted":false,"permission":1,"notification_level":null,"logo_url":"/uploads/default/3724/6981b4a2dd032f5b.png","background_url":""},{"id":14,"name":"Coding Help","color":"652D90","text_color":"000000","slug":"coding-help","topic_count":150,"post_count":4755,"description":"Coding Help: The one place you would really  hope not to get a \"WTF\" solution to your problem. No homework problems please.","description_text":"Coding Help: The one place you would really  hope not to get a \"WTF\" solution to your problem. No homework problems please.","topic_url":"/t/about-the-coding-help-category/236","read_restricted":false,"permission":1,"notification_level":null,"logo_url":"/uploads/default/3722/b802ed27b62097ad.png","background_url":""},{"id":17,"name":"The I-Hate-Oracle Club","color":"A3C00F","text_color":"000000","slug":"the-i-hate-oracle-club","topic_count":15,"post_count":505,"description":"I-Hate-Oracle-Club: Because it's time we senselessly bash someone besides Microsoft.","description_text":"I-Hate-Oracle-Club: Because it's time we senselessly bash someone besides Microsoft.","topic_url":"/t/about-the-the-i-hate-oracle-club-category/628","read_restricted":false,"permission":1,"notification_level":null,"logo_url":"/uploads/default/3731/303bbf4f4d1b8594.png","background_url":""},{"id":18,"name":"CodeSOD","color":"D25372","text_color":"000000","slug":"codesod","topic_count":92,"post_count":3576,"description":"Code Snippet of the Day - self-submissions for code snippets that shouldn't really exist.","description_text":"Code Snippet of the Day - self-submissions for code snippets that shouldn't really exist.","topic_url":"/t/about-the-codesod-category/749","read_restricted":false,"permission":1,"parent_category_id":10,"notification_level":null,"logo_url":"/uploads/default/3726/b15891cb3fb5b9cc.png","background_url":""},{"id":19,"name":"FAQs","color":"B3B4B3","text_color":"000000","slug":"faqs","topic_count":14,"post_count":25,"description":"Frequently mentioned stuff about the forums.","description_text":"Frequently mentioned stuff about the forums.","topic_url":"/t/about-the-faqs-category/774","read_restricted":false,"permission":null,"parent_category_id":3,"notification_level":null,"logo_url":"/uploads/default/3720/47414f90af93ca41.png","background_url":""},{"id":20,"name":"Funny stuff","color":"92278F","text_color":"000000","slug":"funny-stuff","topic_count":125,"post_count":9549,"description":"Funny Stuff: Not exactly a WTF, but not a LOLCAT either","description_text":"Funny Stuff: Not exactly a WTF, but not a LOLCAT either","topic_url":"/t/about-the-funny-stuff-category/1086","read_restricted":false,"permission":1,"notification_level":null,"logo_url":"/uploads/default/3727/ef06c969158480d3.png","background_url":""},{"id":21,"name":"Coder Challenge","color":"3AB54A","text_color":"000000","slug":"coder-challenge","topic_count":16,"post_count":1725,"description":"Sure, you can talk the talk, but can you code the ... erm ... code? Solve and share fun exercises in programming and development.","description_text":"Sure, you can talk the talk, but can you code the ... erm ... code? Solve and share fun exercises in programming and development.","topic_url":"/t/about-the-coder-challenge-category/1104","read_restricted":false,"permission":1,"parent_category_id":14,"notification_level":null,"logo_url":"","background_url":""},{"id":26,"name":"One Post","color":"BF1E2E","text_color":"000000","slug":"one-post","topic_count":449,"post_count":3272,"description":"One post (ideally) per topic. ","description_text":"One post (ideally) per topic. ","topic_url":"/t/about-the-one-post-category/1682","read_restricted":true,"permission":1,"parent_category_id":3,"notification_level":null,"logo_url":"","background_url":""},{"id":25,"name":"Error'd","color":"AB9364","text_color":"000000","slug":"errord","topic_count":73,"post_count":2083,"description":"Error'd - features fun error messages and other visual oddities from the world of IT.","description_text":"Error'd - features fun error messages and other visual oddities from the world of IT.","topic_url":"/t/about-the-errord-category/1579","read_restricted":false,"permission":1,"parent_category_id":10,"notification_level":null,"logo_url":"/uploads/default/4031/d582ce7784d6ae9a.png","background_url":""},{"id":23,"name":"The Lounge","color":"F7941D","text_color":"000000","slug":"the-lounge","topic_count":41,"post_count":5534,"description":"The Frequent Flyers Lounge. Available to Level 3 users and upwards.","description_text":"The Frequent Flyers Lounge. Available to Level 3 users and upwards.","topic_url":"/t/about-the-the-lounge-category/1449","read_restricted":true,"permission":1,"parent_category_id":3,"notification_level":null,"logo_url":"/uploads/default/3714/4d66fa88db26eea5.png","background_url":"/uploads/default/3710/9344b7fa92145810.jpg"},{"id":28,"name":"Programmers' Testing","color":"231F20","text_color":"000000","slug":"programmers-testing","topic_count":16,"post_count":1224,"description":"A group for people to discuss, and solicit testers and comments for, their pet projects.","description_text":"A group for people to discuss, and solicit testers and comments for, their pet projects.","topic_url":"/t/about-the-programmers-testing-category/2278","read_restricted":true,"permission":null,"notification_level":null,"logo_url":"/uploads/default/5763/6431ae8364562fc7.png","background_url":""},{"id":30,"name":"Bot Testing","color":"9EB83B","text_color":"000000","slug":"bot-testing","topic_count":51,"post_count":9974,"description":"Category to separate bot testing out from the rest of the forums.","description_text":"Category to separate bot testing out from the rest of the forums.","topic_url":"/t/about-the-bot-testing-category/3487","read_restricted":true,"permission":null,"parent_category_id":28,"notification_level":null,"logo_url":"","background_url":""},{"id":31,"name":"Flags/Badges","color":"ED207B","text_color":"000000","slug":"flags-badges","topic_count":15,"post_count":643,"description":"Meta-topic to discuss flags and/or badges.","description_text":"Meta-topic to discuss flags and/or badges.","topic_url":"/t/about-the-flags-badges-category/7702","read_restricted":false,"permission":1,"parent_category_id":3,"notification_level":null,"logo_url":"/uploads/default/13757/230e6d4035ddd2d7.png","background_url":""}],"post_action_types":[{"name_key":"bookmark","name":"Bookmark","description":"Bookmark this post","long_form":"bookmarked this post","is_flag":false,"icon":null,"id":1,"is_custom_flag":false},{"name_key":"like","name":"Like","description":"Like this post","long_form":"liked this","is_flag":false,"icon":"heart","id":2,"is_custom_flag":false},{"name_key":"off_topic","name":"Off-Topic","description":"This post is not relevant to the current discussion as defined by the title and first post, and should probably be moved elsewhere.","long_form":"flagged this as off-topic","is_flag":true,"icon":null,"id":3,"is_custom_flag":false},{"name_key":"inappropriate","name":"Inappropriate","description":"This post contains content that a reasonable person would consider offensive, abusive, or a violation of <a href=\"/guidelines\">our community guidelines<\/a>.","long_form":"flagged this as inappropriate","is_flag":true,"icon":null,"id":4,"is_custom_flag":false},{"name_key":"vote","name":"Vote","description":"Vote for this post","long_form":"voted for this post","is_flag":false,"icon":null,"id":5,"is_custom_flag":false},{"name_key":"spam","name":"Spam","description":"This post is an advertisement. It is not useful or relevant to the current topic, but promotional in nature.","long_form":"flagged this as spam","is_flag":true,"icon":null,"id":8,"is_custom_flag":false},{"name_key":"notify_user","name":"Private Message @{{username}}","description":"This post contains something I want to talk to this person directly and privately about. Does not cast a flag.","long_form":"private messaged user","is_flag":true,"icon":null,"id":6,"is_custom_flag":true},{"name_key":"notify_moderators","name":"Something Else","description":"This post requires moderator attention for another reason not listed above.","long_form":"flagged this for moderator attention","is_flag":true,"icon":null,"id":7,"is_custom_flag":true}],"topic_flag_types":[{"name_key":"inappropriate","name":"Inappropriate","description":"This topic contains content that a reasonable person would consider offensive, abusive, or a violation of <a href=\"/guidelines\">our community guidelines<\/a>.","long_form":"flagged this as inappropriate","is_flag":true,"icon":null,"id":4,"is_custom_flag":false},{"name_key":"spam","name":"Spam","description":"This topic is an advertisement. It is not useful or relevant to this site, but promotional in nature.","long_form":"flagged this as spam","is_flag":true,"icon":null,"id":8,"is_custom_flag":false},{"name_key":"notify_moderators","name":"Something Else","description":"This topic requires general moderator attention based on the <a href=\"/guidelines\">guidelines<\/a>, <a href=\"/tos\">TOS<\/a>, or for another reason not listed above.","long_form":"flagged this for moderator attention","is_flag":true,"icon":null,"id":7,"is_custom_flag":true}],"trust_levels":[{"id":0,"name":"new user"},{"id":1,"name":"basic user"},{"id":2,"name":"member"},{"id":3,"name":"regular"},{"id":4,"name":"leader"}],"archetypes":[{"id":"regular","name":"Regular Topic","options":[]},{"id":"banner","name":"translation missing: en.archetypes.banner.title","options":[]}],"user_fields":[{"id":1,"name":"Sex","description":"Sex","field_type":"text","editable":true,"required":false,"show_on_profile":true},{"id":2,"name":"Gender","description":"Gender","field_type":"text","editable":true,"required":false,"show_on_profile":true}]});
            PreloadStore.store("siteSettings",{"title":"What the Daily WTF?","contact_email":"apapadimoulis@inedo.com","logo_url":"//what.thedailywtf.com/uploads/default/8213/dcb3593d1b31ef5e.png","logo_small_url":"//what.thedailywtf.com//uploads/default/8214/16c00f5bd6b57125.png","mobile_logo_url":"","favicon_url":"//what.thedailywtf.com/uploads/default/3/b22d0889376957fa.ico","allow_user_locale":true,"suggested_topics":10,"track_external_right_clicks":false,"ga_universal_tracking_code":"UA-9122028-2","ga_universal_domain_name":"auto","ga_tracking_code":"","ga_domain_name":"","top_menu":"latest|new|unread|bookmarks|top|categories","post_menu":"raw|like|dislike|share|flag|edit|bookmark|delete|admin|reply","post_menu_hidden_items":"","share_links":"twitter|facebook|google+|email","category_colors":"BF1E2E|F1592A|F7941D|9EB83B|3AB54A|12A89D|25AAE2|0E76BD|652D90|92278F|ED207B|8C6238|231F20|808281|B3B5B4|283890","category_style":"bar","enable_mobile_theme":true,"relative_date_duration":7,"category_featured_topics":10,"fixed_category_positions":false,"show_subcategory_list":false,"enable_badges":true,"invite_only":false,"login_required":false,"must_approve_users":false,"enable_local_logins":true,"allow_new_registrations":true,"enable_google_logins":false,"enable_google_oauth2_logins":true,"enable_yahoo_logins":true,"enable_twitter_logins":true,"enable_facebook_logins":true,"enable_github_logins":true,"enable_sso":false,"sso_overrides_avatar":false,"min_username_length":3,"max_username_length":20,"min_password_length":8,"logout_redirect":"","enable_names":true,"invites_per_page":40,"delete_user_max_post_age":60,"delete_all_posts_max":15,"show_email_on_profile":true,"min_post_length":1,"min_private_message_post_length":1,"max_post_length":32000,"min_topic_title_length":4,"max_topic_title_length":255,"min_private_message_title_length":1,"allow_uncategorized_topics":false,"min_title_similar_length":10,"min_body_similar_length":15,"edit_history_visible_to_public":false,"delete_removed_posts_after":24,"traditional_markdown_linebreaks":false,"suppress_reply_directly_below":false,"suppress_reply_directly_above":false,"max_reply_history":3,"experimental_reply_expansion":false,"newuser_max_images":1,"newuser_max_attachments":0,"display_name_on_posts":true,"short_progress_text_threshold":100000,"default_code_lang":"auto","autohighlight_all_code":false,"censored_words":"elgiu|belgium","enable_emoji":true,"emoji_set":"emoji_one","email_time_window_mins":10,"disable_digest_emails":false,"email_in":false,"disable_emails":false,"max_image_size_kb":3072,"max_attachment_size_kb":1024,"authorized_extensions":".jpg|.jpeg|.png|.gif","max_image_width":690,"max_image_height":500,"prevent_anons_from_downloading_files":false,"allow_profile_backgrounds":true,"allow_uploaded_avatars":true,"allow_animated_avatars":false,"tl1_requires_read_posts":30,"enable_long_polling":true,"long_polling_base_url":"/","background_polling_interval":60000,"polling_interval":3000,"anon_polling_interval":15000,"flush_timings_secs":10,"verbose_localization":false,"tos_url":"","privacy_policy_url":"","faq_url":"http://what.thedailywtf.com/t/write-your-faq/370","maximum_backups":3,"version_checks":true,"suppress_uncategorized_badge":true,"min_search_term_length":3,"topic_views_heat_low":1000,"topic_views_heat_medium":2000,"topic_views_heat_high":5000,"topic_post_like_heat_low":0.5,"topic_post_like_heat_medium":1.0,"topic_post_like_heat_high":2.0,"history_hours_low":12,"history_hours_medium":24,"history_hours_high":48,"cold_age_days_low":14,"cold_age_days_medium":60,"cold_age_days_high":120,"global_notice":"","show_create_topics_notice":true,"available_locales":"ar|cs|da|de|en|es|fi|fr|he|id|it|ja|ko|nb_NO|nl|pl_PL|pt|pt_BR|ro|ru|sq|sv|te|tr_TR|uk|zh_CN|zh_TW"});
            PreloadStore.store("customHTML",{"top":"","footer":""});
            PreloadStore.store("banner",{});
            PreloadStore.store("customEmoji",["Body is limited to 32000 characters; you entered 57782."]);
          </script>
    

    @Onyx said:

    Now, if they just had strings I'd keep it that way most likely. With integers, I can either map it to an enum, or map it to an array of strings. Enums turn out to be less work, and easier to modify as needed. But given that this shit is in the DB I hope it will be pretty constant.

    Covered in http://what.thedailywtf.com/t/may-contain-a-hash-of-options/6830/15:

    why bother with the tedious mapping

    It's for storing them in the db. Except that they accidentally also used the ints as parameters in several places, making the whole thing an exercise in futility.



  • TL;DR;
    but
    @Onyx said:

    "display_username": "11 replies",

    :wtf: ^ :wtf:



  • Yo, paging @11 replies up in this topic, yo.





  • a little less :wtf:
    i guess calling it label it's too mainstream



  • @Jarry said:

    a little less :wtf:
    i guess calling it label is too mainstream

    ftfy


Log in to reply