Zombies, Zombie Pigmen, Skeletons, and Wither Skeletons all have an inner limit to their (melee) attack area. This means that if you get too close to them, they aren't able to hit you. It's difficult to do normally, due to the attack knockback, but if you use an item with a knockback modifier it's easy.
/give @p minecraft:bedrock 1 0 {AttributeModifiers:[{AttributeName:"generic.knockbackResistance",Name:"generic.knockbackResistance",Amount:100,Operation:0,UUIDLeast:713578,UUIDMost:353488}]}"
sounds like MC-97754