<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Joe Evans on Medium]]></title>
        <description><![CDATA[Stories by Joe Evans on Medium]]></description>
        <link>https://medium.com/@evonsdesigns?source=rss-134903d2861f------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*GUv36zV9lvH4ssnY.</url>
            <title>Stories by Joe Evans on Medium</title>
            <link>https://medium.com/@evonsdesigns?source=rss-134903d2861f------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 14:39:29 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@evonsdesigns/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Python Zip Single File]]></title>
            <link>https://evonsdesigns.medium.com/python-zip-single-file-d4b5b26ce1aa?source=rss-134903d2861f------2</link>
            <guid isPermaLink="false">https://medium.com/p/d4b5b26ce1aa</guid>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Joe Evans]]></dc:creator>
            <pubDate>Wed, 24 Apr 2019 18:06:31 GMT</pubDate>
            <atom:updated>2019-04-24T18:06:31.419Z</atom:updated>
            <content:encoded><![CDATA[<p>Zipping files in Python is easy, but I had trouble finding good examples. Below is a simple example for creating a zip file from a single file.</p><pre>import zipfile</pre><pre>zipFileName=&#39;your-zip-file.zip&#39;<br>fileToBeZipped=&#39;file.jpeg&#39;</pre><pre>zipfile.ZipFile(zipFileName, mode=&#39;w&#39;).write(fileToBeZipped)</pre><p><a href="https://docs.python.org/3/library/zipfile.html">Official Docs</a> (Python 3.7.3)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d4b5b26ce1aa" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Google Analytics: Stop using ClientID from iFrame]]></title>
            <link>https://evonsdesigns.medium.com/google-analytics-stop-using-clientid-from-iframe-a6572a5667f3?source=rss-134903d2861f------2</link>
            <guid isPermaLink="false">https://medium.com/p/a6572a5667f3</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[google-analytics]]></category>
            <category><![CDATA[analytics]]></category>
            <category><![CDATA[google]]></category>
            <category><![CDATA[universal-analytics]]></category>
            <dc:creator><![CDATA[Joe Evans]]></dc:creator>
            <pubDate>Fri, 22 Mar 2019 20:38:26 GMT</pubDate>
            <atom:updated>2019-03-22T20:39:39.171Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/540/1*t_lgKA7l_YlfaP_FF_nKAQ.png" /></figure><p>I ran into a problem recently where Google Analytics (analytics.js) was loaded in an iFrame header of an application, setting up the _ga cookie and ClientID. From the perspective of my main application’s analytics, I was not seeing any “New Users” on the Analytics dashboard, but the iFrame header application was.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*O1xdBS3WBAt2fqzjY46BTw.png" /><figcaption>Example using Medium.com, depicting an iFrame header and the application. Note: Just for visualization purposes.</figcaption></figure><p>First of all, I should mention that “New Users” metric <a href="https://www.optimizesmart.com/understanding-users-in-google-analytics/">isn’t particularly useful</a>. An existing user could clear their browsing data and appear as a new user. Keep that in mind if you show off stats from Google Analytics.</p><p>The problem is simple; whichever analytics loads first will create the cookie, registering the new user. I did not have a way to make these calls synchronous, so I had to look at an alternative solution.</p><p>I was able to define a custom GA tracking cookie name to use. This guaranteed I would not run into issues with the iFrame application (which used the default “_ga” cookie).</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bd46611de3fa1c64fd5468afd954edc9/href">https://medium.com/media/bd46611de3fa1c64fd5468afd954edc9/href</a></iframe><p>After making this change, I immediately started seeing new users show up on my application’s analytics.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*r7MQh0NJRRG6uNjZbedf-g.png" /><figcaption>At 1:00pm my change was integrated. You can see the new users metric comes back right away.</figcaption></figure><p>Read more about the cookie configuration in the <a href="https://developers.google.com/analytics/devguides/collection/analyticsjs/cookies-user-id#configuring_cookie_field_settings">analytics.js docs</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a6572a5667f3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[JUnit: Selectively Ignore Logging]]></title>
            <link>https://evonsdesigns.medium.com/junit-selectively-ignore-logging-51e7f68113de?source=rss-134903d2861f------2</link>
            <guid isPermaLink="false">https://medium.com/p/51e7f68113de</guid>
            <category><![CDATA[java]]></category>
            <category><![CDATA[junit]]></category>
            <category><![CDATA[slf4j]]></category>
            <category><![CDATA[log4j]]></category>
            <category><![CDATA[powermockito]]></category>
            <dc:creator><![CDATA[Joe Evans]]></dc:creator>
            <pubDate>Wed, 13 Mar 2019 16:08:04 GMT</pubDate>
            <atom:updated>2019-03-13T16:08:04.155Z</atom:updated>
            <content:encoded><![CDATA[<p>Logs in testing are not so great. They muddy the console when you have an error, forcing you to scroll down to where you can see the actual stack trace. There are a few ways to resolve this.</p><h3>Hide All Logs! I don’t care!</h3><ol><li>Create a file <strong>src/test/resources/logback-test.xml</strong></li><li>In <strong>logback-text.xml</strong>, add &lt;configuration /&gt;</li><li>Voila! No more logs in tests.</li></ol><h3>Wait a minute, I want logs for some of my tests…</h3><p>When you want to hide logs on some tests, you can achieve this using PowerMockito. We override the LoggerFactory and return our own mocked logger.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f6a201f5758574af5b1112180ecabfb3/href">https://medium.com/media/f6a201f5758574af5b1112180ecabfb3/href</a></iframe><p>Warning: Some of your dependent libraries may be using the LoggerFactory to obtain a Logger. If you run into this, you can change your PowerMockito.when(…) function to handle any class, using Hamcrest matchers:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d081ccee077e3a7c0b8cb55f97bbef78/href">https://medium.com/media/d081ccee077e3a7c0b8cb55f97bbef78/href</a></iframe><p>That should handle dependencies that are throwing NPEs from their logger calls.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=51e7f68113de" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ObjectMapper Unit Testing configured Mapper Features]]></title>
            <link>https://evonsdesigns.medium.com/objectmapper-unit-testing-configured-mapper-features-33e9bec0312e?source=rss-134903d2861f------2</link>
            <guid isPermaLink="false">https://medium.com/p/33e9bec0312e</guid>
            <category><![CDATA[java]]></category>
            <category><![CDATA[pojo]]></category>
            <category><![CDATA[json]]></category>
            <category><![CDATA[objectmapper]]></category>
            <category><![CDATA[jackson]]></category>
            <dc:creator><![CDATA[Joe Evans]]></dc:creator>
            <pubDate>Mon, 18 Feb 2019 19:23:00 GMT</pubDate>
            <atom:updated>2019-03-12T18:06:20.396Z</atom:updated>
            <content:encoded><![CDATA[<h3>ObjectMapper: Unit Testing configured Mapper Features</h3><figure><img alt="Image result for unit testing comic" src="https://cdn-images-1.medium.com/proxy/1*B3erTxbwh7Lm3KrWvlR2zA.gif" /></figure><p>Jackson <a href="https://fasterxml.github.io/jackson-databind/javadoc/2.7/com/fasterxml/jackson/databind/ObjectMapper.html">ObjectMapper</a> comes with extendable <a href="https://fasterxml.github.io/jackson-databind/javadoc/2.7/com/fasterxml/jackson/databind/MapperFeature.html">MapperFeatures</a>. When I first jumped into using these, I found no obvious methods on the ObjectMapper to easily retrieve the values for these features, but after a few google searches, I am able to share a very easy way to retrieve and test them.</p><p>Given the following simple class PojoMapper, we can write equally simple tests.</p><h3>PojoMapper.java</h3><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1108acbb1bea47be5026c14fc7630446/href">https://medium.com/media/1108acbb1bea47be5026c14fc7630446/href</a></iframe><h3>PojoMapperTest.java</h3><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6db905dc99fba6d0240a494579acb761/href">https://medium.com/media/6db905dc99fba6d0240a494579acb761/href</a></iframe><p>To test the addition of MapperFeature.<em>ACCEPT_CASE_INSENSITIVE_PROPERTIES, </em>we need to grab the <a href="https://fasterxml.github.io/jackson-databind/javadoc/2.8/com/fasterxml/jackson/databind/DeserializationConfig.html">DeserializationConfig</a> from the ObjectMapper.</p><p>The DeserializationConfig is accessible directly from the ObjectMapper. From there, we use the function <strong>isEnabled(</strong><a href="https://fasterxml.github.io/jackson-databind/javadoc/2.8/com/fasterxml/jackson/databind/DeserializationFeature.html"><strong>DeserializationFeature</strong></a><strong> f)</strong> to check for toggled features.</p><h3>Using JsonParser.Features</h3><p>These features act a little bit differently from MapperFeatures. The classes are different so the <a href="https://fasterxml.github.io/jackson-databind/javadoc/2.8/com/fasterxml/jackson/databind/DeserializationConfig.html#isEnabled(com.fasterxml.jackson.databind.DeserializationFeature)"><strong>isEnabled(DeserializationFeature f)</strong></a><strong> </strong>function used above won’t work. There is an alternative <a href="https://fasterxml.github.io/jackson-databind/javadoc/2.8/com/fasterxml/jackson/databind/DeserializationConfig.html#isEnabled(com.fasterxml.jackson.core.JsonParser.Feature,%20com.fasterxml.jackson.core.JsonFactory)"><strong>isEnabled(JsonParser.Feature f, JsonFactory factory)</strong></a> function that takes a Feature and a JsonFactory.</p><p>Let’s add to the previous example:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e56530f5ef26e26a9b99a4cab0c76734/href">https://medium.com/media/e56530f5ef26e26a9b99a4cab0c76734/href</a></iframe><p>Our test doesn’t change much. We use a different isEnabled function, using the provided JsonFactory from the ObjectMapper.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a97b0c55aa57550f3ce59a24410b50d6/href">https://medium.com/media/a97b0c55aa57550f3ce59a24410b50d6/href</a></iframe><p>That’s it. Happy marshalling!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=33e9bec0312e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Spring Boot: Include Transient fields in Jackson Serialization]]></title>
            <link>https://evonsdesigns.medium.com/spring-boot-include-transient-fields-in-jackson-serialization-4d6e24571585?source=rss-134903d2861f------2</link>
            <guid isPermaLink="false">https://medium.com/p/4d6e24571585</guid>
            <category><![CDATA[java]]></category>
            <category><![CDATA[spring]]></category>
            <category><![CDATA[spring-boot]]></category>
            <dc:creator><![CDATA[Joe Evans]]></dc:creator>
            <pubDate>Mon, 16 Apr 2018 17:59:46 GMT</pubDate>
            <atom:updated>2019-03-12T15:30:24.941Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*6TDt__s--hkzQsHm.jpg" /></figure><p>If this is your first foray into Spring Boot with Hibernate, you may notice that you are not getting all the properties serialized from your POJOs. Specifically, fields with Hibernate’s `@Transient` annotation are ignored during serialization.</p><p>So what is going on here? We want our Hibernate to ignore the fields, but not Jackson! To make Jackson serialize those fields, we have to do a few things:</p><ol><li>Add necessary JSON annotations to the POJO fields</li><li>Add an ObjectMapper bean to the application</li></ol><h3>Adding JSON Annotations</h3><p>You may have Transient annotations on both your fields and their getters, but you only need to define a single annotation, `@<a href="https://fasterxml.github.io/jackson-annotations/javadoc/2.6/com/fasterxml/jackson/annotation/JsonGetter.html">JsonGetter</a>`, on your field getter:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a6393553899be5b2d82f3d5f13f64fd2/href">https://medium.com/media/a6393553899be5b2d82f3d5f13f64fd2/href</a></iframe><p>With the expected output of</p><pre>{<br>   &quot;id&quot;: &quot;...&quot;,<br>   &quot;transientProperty&quot;: &quot;SomethingToInclude&quot;<br>}</pre><p>But, we’re not there yet. If you test your endpoint after adding these fields, you’ll notice the transient fields still do not show up.</p><h3>Add ObjectMapper for Hibernate 5</h3><p>Transient fields won’t show up yet because Jackson is still treating them as ignored fields for serialization.</p><p>For the next step, open up your Application.java file, and add the following bean. You may need to include dependencies, specifically jackson-datatype-hibernate#. You can use 3,4, or version 5 here. For the example, I will use jackson-datatype-hibernate5.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/43930754b448f059d0e46cff41aab4bd/href">https://medium.com/media/43930754b448f059d0e46cff41aab4bd/href</a></iframe><h3>That’s it!</h3><p>Start up your Spring application and test the endpoint. You should now see the transient fields with the JsonGetter annotation show up in your endpoint response.</p><p><strong>To see code examples, </strong><a href="https://gist.github.com/evonsdesigns/a79f81868fe43ca32ee4eb7341d8b635"><strong>click here</strong></a><strong>.</strong></p><h3>Dependencies Used</h3><ul><li>jackson-datatype-hibernate5@2.9.5</li><li>jackson-databind@2.9.5</li><li>jackson-annotations@2.9.5</li><li>spring-boot-starter@2.0.1.RELEASE</li><li>spring-boot-starter-web@2.0.1.RELEASE</li><li>spring-boot-starter-data-jpa@2.0.1.RELEASE</li></ul><h3>Problems with this Solution</h3><p>This doesn’t work when your entity implements an interface with the Transient annotation on the getter. I haven’t found a way to get around this yet.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4d6e24571585" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Spring JPA One-to-Many Query Examples with Property Expressions]]></title>
            <link>https://evonsdesigns.medium.com/spring-jpa-one-to-many-query-examples-281078bc457b?source=rss-134903d2861f------2</link>
            <guid isPermaLink="false">https://medium.com/p/281078bc457b</guid>
            <category><![CDATA[spring-boot]]></category>
            <category><![CDATA[jpa]]></category>
            <category><![CDATA[spring-data]]></category>
            <category><![CDATA[java]]></category>
            <dc:creator><![CDATA[Joe Evans]]></dc:creator>
            <pubDate>Mon, 12 Feb 2018 21:42:59 GMT</pubDate>
            <atom:updated>2020-11-05T23:08:09.493Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/202/1*Fx3uQ4pGCNmjt0f_XPZVKw.png" /></figure><p>In this article, I will explain some of the ways you can build out your Spring JPA repositories.</p><p>Assume we have Person and Address entities and each Person can have multiple Addresses. You want to look up Persons by a specific zip code. How can you write the query in your Repository class to traverse the database to find the result set? There are many ways to achieve this, but I will only focus on two: an ugly way, and a beautiful way.</p><p>Let’s take the Person entity class for example. Assume a <strong>Person </strong>class has a list of Addresses of type <strong>Address:</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/38097cefa185548efccd611cdfd5fdad/href">https://medium.com/media/38097cefa185548efccd611cdfd5fdad/href</a></iframe><p>Hibernate will automatically generate entity tables and association tables for you, so you have three tables created:</p><p>- person<br>- address<br>- person_addresses</p><p>If we had to look up zip codes the ugly way, with a native query, we could accomplish it like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fcf2522f81c2293e3de0a5558c578ab0/href">https://medium.com/media/fcf2522f81c2293e3de0a5558c578ab0/href</a></iframe><blockquote><strong>Yuck</strong>. Given how much we get from Spring for free, there has to be a better way to achieve the same outcome.</blockquote><p>Good news! We can get the same result set with property expressions. By defining the following method in our repository interface, we can find all people by zip code:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/57c176ffb3681469295844f508a8a6ef/href">https://medium.com/media/57c176ffb3681469295844f508a8a6ef/href</a></iframe><p>IntelliJ even helps by listing valid keywords:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/287/1*NTGylHSDvJqMz4egQwVnIg.png" /><figcaption>As you type out the method name, you will get a huge list of keywords mapping to the properties on your entity.</figcaption></figure><p>JPA uses a resolution algorithm to traverse the properties by interpreting the method header. This works for most cases, but sometimes you may need to explicitly define traversal points. This can be accomplished by using _ in the method header.</p><pre>List&lt;Person&gt; findByAddress_ZipCode(String zipCode);</pre><blockquote>JPA will return all Persons with at least one Address that has the given zip code.</blockquote><p>Wait a minute — there’s a lot more to an address than a zip code. What if we want to search by street address AND zip code?</p><pre>List&lt;Person&gt; findByAddress_ZipCode_AndAddress_StreetAddress(String zipCode, String streetAddress);</pre><blockquote>JPA will return all Persons with at least one Address that has the given zip code and street address.</blockquote><p>For more on this topic, read the <a href="https://docs.spring.io/spring-data/jpa/docs/1.5.0.RELEASE/reference/html/repositories.html">Working with Spring Data Repositories docs</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=281078bc457b" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>