<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-5851758904031553528</id><updated>2011-11-27T18:47:37.242-05:00</updated><title type='text'>GNU Guy</title><subtitle type='html'>The fun and folly of an inexperienced software engineer using open source tools in the wild, wide, world of web development</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://gnuguy.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5851758904031553528/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://gnuguy.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Christopher Suter</name><uri>http://www.blogger.com/profile/04871226658814740333</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://2.bp.blogspot.com/_tPauibiC9jY/ShRRusOp2wI/AAAAAAAAAHo/MgMWJX3f8Fc/S220/chris_suter.png'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>3</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-5851758904031553528.post-6089364114244854362</id><published>2009-05-20T13:59:00.006-04:00</published><updated>2009-05-20T14:47:22.307-04:00</updated><title type='text'>Java/JSON numeric data types</title><content type='html'>Working on a Java-based project for &lt;a href='listen.grooveshark.com'&gt;Grooveshark&lt;/a&gt;, I ran into an issue with the Java &lt;a href='www.json.org/java'&gt;JSON library&lt;/a&gt;'s numeric datatype parsing. My data source is a pretty run-of-the-mill MySQL database and, as you may know, if you have a table with an INT column (very common for primary key ID fields), Java imports those values as Longs. Now, my code is basically taking data from MySQL, serializing it into JSON text and storing it in memcached for later retrieval. The problem came about as follows: I would load the JSON string from memcached (in this case a list of numbers from an INT UNSIGNED PRIMARY KEY column), deserialize it, and convert it from a JSON Array to a Java &lt;code&gt;List&amp;lt;Long&amp;gt;&lt;/code&gt;. At the same time, I had another &lt;code&gt;List&amp;lt;Long&amp;gt;&lt;/code&gt; of values coming in from the database, and I performed a simple check to see if one list contained the other as a subset. Say the JSON-based list was called &lt;code&gt;jsonIDs&lt;/code&gt; and the list from the DB &lt;code&gt;dbIDs&lt;/code&gt; -- I called &lt;code&gt;jsonIDs.containsAll(dbIDs)&lt;/code&gt;. In this particular case, both lists had only one element and by logging them to stdout, I could *see* that they contained the same numerical value. Yet despite my pleas and screaming, &lt;code&gt;jsonIDs.containsAll(dbIDs)&lt;/code&gt; returned false. Infuriating! So finally, I wound up writing my own nested for loops to do the comparisons by hand, and sure enough, when I did the comparison on individual elements pulled from the respective lists, I got an exception --&lt;br /&gt;&lt;code&gt;java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.Long&lt;/code&gt;&lt;br /&gt;Apparently, my &lt;code&gt;List&amp;lt;Long&amp;gt;&lt;/code&gt; was nothing of the sort. I thought and thought about where my objects were actually coming from. The DB IDs were clearly coming straight from the database and there couldn't be an issue there. It had to be the JSON-based list. So I downloaded the source code from json.org and dug around. Sure enough, the &lt;code&gt;JSONTokener&lt;/code&gt; class, responsible for parsing JSON text into a Java object was the source of the problem. In parsing what it believes to be numeric text, it goes through a series of checks to determine the type of number -- hex, octal, double, and finally long. Unfortunately, when determined to be a whole number and despite being parsed as a long, the &lt;code&gt;JSONTokener&lt;/code&gt; makes a final check to see if precision is lost by casting to an &lt;code&gt;Integer&lt;/code&gt;. If not, the value is cast to an Integer and returned, and this was the source of my problem. So I pulled the json.org source code into my project and made an easy one-line fix to prevent this cast altogether. Now my (hacked) JSON code will return a &lt;code&gt;long&lt;/code&gt; no matter what the (whole-number) value, which may not be ideal in general (hence the original behavior) but does the trick for me. All the numeric values I'm serializing are going to be &lt;code&gt;long&lt;/code&gt;s anyway. What I still don't get is why, when loading an &lt;code&gt;Integer&lt;/code&gt; into a &lt;code&gt;List&amp;lt;Long&amp;gt;&lt;/code&gt;, the object is allowed to keep its &lt;code&gt;Integer&lt;/code&gt; type. Shouldn't this object be cast before it can be added to the &lt;code&gt;List&lt;/code&gt;? I'm stumped on this one, but hey, my code is working again so I'm movin' on. Any ideas?&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5851758904031553528-6089364114244854362?l=gnuguy.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://gnuguy.blogspot.com/feeds/6089364114244854362/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5851758904031553528&amp;postID=6089364114244854362' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5851758904031553528/posts/default/6089364114244854362'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5851758904031553528/posts/default/6089364114244854362'/><link rel='alternate' type='text/html' href='http://gnuguy.blogspot.com/2009/05/javajson-numeric-data-types.html' title='Java/JSON numeric data types'/><author><name>Christopher Suter</name><uri>http://www.blogger.com/profile/04871226658814740333</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://2.bp.blogspot.com/_tPauibiC9jY/ShRRusOp2wI/AAAAAAAAAHo/MgMWJX3f8Fc/S220/chris_suter.png'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5851758904031553528.post-6740147699160162804</id><published>2008-03-15T15:02:00.010-04:00</published><updated>2008-03-15T15:35:18.145-04:00</updated><title type='text'>Neat del.icio.us tip</title><content type='html'>I found a cool new way to use &lt;a href="http://del.icio.us"&gt;del.icio.us&lt;/a&gt;! I've had an account over at &lt;a href="http://del.icio.us"&gt;del.icio.us&lt;/a&gt; for probably a year and while I (somewhat) frequently tag things, I rarely use this service to &lt;span style="font-style: italic;"&gt;get to&lt;/span&gt; web sites. I'm much more likely to use my google toolbar. However it occurred to me yesterday that 95% of the time, when I open a fresh browser window, there are maybe 5 places I'm likely to be headed. Traditionally, I've had my browser home page set to gmail.com and this choice is pretty arbitrary - although it is one of the 5 places I'm usually headed to when I hit my browser icon.&lt;br /&gt;&lt;br /&gt;So here's the tip:&lt;br /&gt;I created a special tag ("favorite" as it were) and tagged each of these special sometimes-homepages with this special tag. Then I set my browser homepage to &lt;a href="http://del.icio.us/cgs1019/favorite"&gt;http://del.icio.us/cgs1019/favorite&lt;/a&gt;.  Now when I open my browser, I've got my hand-picked set of likely destinations.&lt;br /&gt;&lt;br /&gt;If you don't have a &lt;a href="http://del.icio.us"&gt;del.icio.us&lt;/a&gt; account, you should! It's a great way to keep track of all the sites you're interested in without having a Bookmarks menu that goes down to the floor. Also, it's a great way to utilize this awesome tip which I went to so much trouble to share.&lt;br /&gt;So check it out!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5851758904031553528-6740147699160162804?l=gnuguy.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://gnuguy.blogspot.com/feeds/6740147699160162804/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5851758904031553528&amp;postID=6740147699160162804' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5851758904031553528/posts/default/6740147699160162804'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5851758904031553528/posts/default/6740147699160162804'/><link rel='alternate' type='text/html' href='http://gnuguy.blogspot.com/2008/03/neat-delicious-tip.html' title='Neat del.icio.us tip'/><author><name>Christopher Suter</name><uri>http://www.blogger.com/profile/04871226658814740333</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://2.bp.blogspot.com/_tPauibiC9jY/ShRRusOp2wI/AAAAAAAAAHo/MgMWJX3f8Fc/S220/chris_suter.png'/></author><thr:total>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5851758904031553528.post-8014956160719550815</id><published>2008-03-10T00:12:00.000-04:00</published><updated>2008-03-10T00:22:52.850-04:00</updated><title type='text'>Hello World</title><content type='html'>This will be my obligatory, self-referential, initial meta-post here on GNU Guy. Those to come will be wrought with tales from the trenches of &lt;a href="http://www.grooveshark.com"&gt;a little internet startup&lt;/a&gt; in Gainesville, and anything else I feel compelled to share. I am an otherwise utterly inexperienced and unqualified software engineer. My degree is in mathematics and my interest in software has always been recreational, however through a seemingly unlikely sequence of events, I can now be found quite thoroughly embedded in the zany world of open source software and web development. Sometimes I sound like I really know what I'm talking about (I do!) and sometimes I sound like I really have no idea what I'm talking about (I don't!). It's fun; I hope to recreate a little of it here.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5851758904031553528-8014956160719550815?l=gnuguy.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://gnuguy.blogspot.com/feeds/8014956160719550815/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5851758904031553528&amp;postID=8014956160719550815' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5851758904031553528/posts/default/8014956160719550815'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5851758904031553528/posts/default/8014956160719550815'/><link rel='alternate' type='text/html' href='http://gnuguy.blogspot.com/2008/03/hello-world.html' title='Hello World'/><author><name>Christopher Suter</name><uri>http://www.blogger.com/profile/04871226658814740333</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://2.bp.blogspot.com/_tPauibiC9jY/ShRRusOp2wI/AAAAAAAAAHo/MgMWJX3f8Fc/S220/chris_suter.png'/></author><thr:total>1</thr:total></entry></feed>
